Forums

How to make Required Field - Help?

saf01 16 Nov, 2007
Hi. Please can someone help? I am using the following Form Javascript:
function ShowReg(op) {
  document.getElementById('Ford').style.display='none';
  document.getElementById('Vauxhall').style.display='none';

  if (op == 1) {
    document.getElementById('Ford').style.display="block";
  }
  if (op == 2) {
    document.getElementById('Vauxhall').style.display="block";
  }
}
And the following Form HTML:
<select id="choice" onChange="ShowReg(this.selectedIndex)">
  <option value='0'>Select Car Make
  <option value="1">Ford
  <option value="2">Vauxhall
</select>
<br>
<div id="Ford" style="display:none">
  Ford Registration No. <input type="text" id="FordReg" value="">
  What is Your Surname. <input name="txtlname" type="text" id="txtlname">
<input type="submit" name="Submit" value="Submit">
</div>
<div id="Vauxhall" style="display:none">
  Vaxhaull Registration No. <input type="text" id="VauxhallReg" value="">
<input type="submit" name="Submit" value="Submit">
</div>
How do I make the Input fields (FordReg,txtlname,VauxhallReg) in the form above Required? I appreciate your help. If I turn on Validation and add the field names in the required field, I get "Object doesn't support this property or method" error when I run the form. Please help.

Post edited by: saf01, at: 2007/11/16 13:35

Edited to add code tags.<br><br>Post edited by: GreyHead, at: 2007/11/16 13:53
GreyHead 16 Nov, 2007
Hi saf01,

It's nto easy to diagnose JavaScript errors without acces to the page (and not always easy then). I'd suggest that you install FireBug on FireFox to see what's happening.

I can see that you haven't closed your <option> tags, and the Vauxhall input field doesn't have a name. I suggest that you clean up your html, remove the ShowReg JavaScript temporarily to get the form working smoothly, then replace ShowReg and debug that.

Bob
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount

{item:title} {images:#}