Jump to content

Recommended Posts

i'm using this script code, i need to use the form field id's instead of the name. how can I do that?

 

<script type="text/javascript">
function validate(form) {
  var city = form.city.value;
  var zip = form.zip.value;
  if(city == "") {
    inlineMsg('city','<strong>Error:</strong><br />Enter your city.',6);
    return false;
  }
  if(zip == "") {
  inlineMsg('zip','<strong>Error:</strong><br />Enter your US or CAN Zip.',6);
  return false;
  }
  return true;
}
</script>

??? Sorry, I'm not following.

 

form.city.value; looks for the form field with "name=city" in it. i'd like for it to look for the "id" instead, since I have other code that requires the form field name to be formated a name=add[city] in which the javascript can not detect. i tried changing form.city.value to document.getElementById(city) and putting id=city in the form input code but that didn't work

<script type="text/javascript">
function validate(form) {
  var city = form.getElementById("city").value;
  var zip = form.getElementById("zip").value;
  if(city == "") {
    inlineMsg('city','<strong>Error:</strong><br />Enter your city.',6);
    return false;
  }
  if(zip == "") {
     inlineMsg('zip','<strong>Error:</strong><br />Enter your US or CAN Zip.',6);
     return false;
  }
  return true;
}
</script>

<script type="text/javascript">
function validate(form) {
  var city = form.getElementById("city").value;
  var zip = form.getElementById("zip").value;
  if(city == "") {
    inlineMsg('city','<strong>Error:</strong><br />Enter your city.',6);
    return false;
  }
  if(zip == "") {
     inlineMsg('zip','<strong>Error:</strong><br />Enter your US or CAN Zip.',6);
     return false;
  }
  return true;
}
</script>

 

thanks that worked, but i had to use document. instead of form.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.