Frage

I need to check if the value of field patientid is empty or null and print an alert.

Somehow the code below is not working:

<td width="75">Patient ID<font color="red">*</font></td>
<td width="166"><form:input path="patientid"/></td>

Could you please help me out?

War es hilfreich?

Lösung

<form:input path="patientid"/> is not html.

This should get you started:

<td width="75">Patient ID<font color="red">*</font></td>
<td width="166"><input type="text" id="patientid" onchange="
   this.value==='' && alert( 'I am empty' );
"/></td>

Or you could try to do this:

<td width="75">Patient ID<font color="red">*</font></td>
<td width="166"><input type="text" id="patientid" onchange="
   this.value==='' && (this.value='I cannot be empty');
"/></td>

Andere Tipps

To check if a input value is empty just do the following:

    if(document.getElementById("yourInputsId").value !=""){
      //do stuff if its not empty}
    else{
     //do other Stuff
    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top