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[]'});


can anyone help me?

thanks in advance =)


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;


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

This question has already been answered. Start a new discussion instead.