Hi!!
i want to validate a list box onthe onblur event and if no value is selected , display a message on the left using <span> and innerHTML


here's what i have written

<html>
<head>
<script type="text/javascript">

function validateCB()
 {
  if(document.rec.loc.options.selectedIndex = = 0)
   {
    alert(" hi");
    return false;
   }
   else
    return true;
  }


function validatePID(inputfield, helptext)
 {
  if(inputfield.value.length !=9)
`  {
    if(helptext != null)
     helptext.innerHTML = "please enter excatly 9 digits";
     return false;
   }
  else
   {
     if(helptext != null)
     helptext.innerHTML = "";
     return true;

  }
}

</script>

</head>

<form method = "post" action="rec.asp" id="rec" name="rec">
<table>
 <tr>
 <td>
  <input id='pid' name='pid' onblur="validatePID(this,document.getElementById('pid_help'))">
  <span id ="pid_help" class="help" > </span> <br> <br>
</td>


<td>
<select id='loc' name='loc' onblur="validateCB()"> <span id="loc_help"> 
<option value = ' ' selected > select location </option>
<option value = 'abcd' selected > abcd </option>
<option value = '1234' selected > 1234 </option>
</td>
</table>

</form>
</html>

well when i was doing this at work... when i entered less than 9 digits in the PID box..it dispalyed text on the left saying please enter 9 digits.. that's what i want to happen, if a user doesn't select a value from the list as well...i tried writing the code for it..but it didnt' work... so i just wrote the alert code..which was working ..but it isnt' here...
dont' know where am i going wrong...
please help !!
thank's....

<html>
<head>
<script type="text/javascript">
function validateCB(loctext)
 {
  if(document.rec.loc.value=='')
   {
   	 loctext.innerHTML = "please select one option";
    return false;
   } 
   else
    return true;
  }


function validatePID(inputfield, helptext)
 {
  if(inputfield.value.length !=9){
    if(helptext != null)
     helptext.innerHTML = "please enter excatly 9 digits";
     return false;
   }
  else
   {
     if(helptext != null)
     helptext.innerHTML = "";
     return true;

  }
}

</script>

</head>

<form method = "post" action="rec.asp" id="rec" name="rec">
<table>
 <tr>
 <td>
  <input id='pid' name='pid' onblur="validatePID(this,document.getElementById('pid_help'))">
  <span id ="pid_help" class="help" > </span> <br> <br>
</td>
</tr>
<tr>
<td>
<select id='loc' name='loc' onblur="validateCB(document.getElementById('loc_help'))">
<option value = '' selected> select location </option>
<option value = 'abcd'> abcd </option>
<option value = '1234'> 1234 </option>
</select><span id="loc_help"> </span>
</td>
</tr>
</table>

</form>
</html>
This article has been dead for over six months. Start a new discussion instead.