hi there,

im a php trainee and really need a help in my javascript ..anyone?

i have my code here that injects a patient name ..i need to know if the patient is already injected..if so..it should not be allowed and should pop an alert that say...'sorry the name has already been added'

function AddPatienttoList()
{
	//alert('add patient list');
	var nametoadd = $('Autopatient_getlist').get('value');
	var nameId = $('patient_getlistno').get('value');
	if (nameId=='')
	{
		alert('Cannot Add blank or Name not on List');
		return false;
	}
	var hold = new Element ('div',{'name':'hold'+nameId, 'id':'hold'+nameId});
	var optionhold = new Element ('div',{'class':'list', 'style':'display:inline','name':'optionhold', 'id':'optionhold'});
	var button = new Element ('input',{'type':'button', 'id':'removepatient', 'value':'X', 'style':'width 128px', 'class':'kwbutton', 'onclick':'RemovePatientfromList('+nameId+')'});
	var optioncontent = new Element ('div',{'class':'list', 'style':'display:inline','name':'patientlist', 'id':'patientlist','html':nametoadd});
	var optioncontentvalue = new Element ('input',{'type':'hidden', 'value':nameId, 'id':'patientlistvalue[]','name':'patientlistvalue[]'});
	
	optioncontentvalue.inject(hold);
	button.inject(optionhold);
	optioncontent.inject(optionhold);
	optionhold.inject(hold);
	hold.inject($('patient_listto'));
	$('Autopatient_getlist').value='';
	$('patient_getlistno').value='';

}

can anyone help me?

thanks in advance =)

Recommended Answers

All 2 Replies

jHappy,

On the basis that nameId is unique and names are't (there could be two John Smiths), then try this, immediately below your nameid=='' trap:

if( $('hold'+nameId) ){
		alert('Patient has already been added.');
		return false;
	}

Airshow

hi airhsow,

thank you very much =) ..yeah you got a point

also, i did some getElements - to get the previous added elements then compare to it the one to be added.

thank you i got it working already

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.