Author Topic: javascript multiple form validation  (Read 750 times)

Offline tellmore

  • Level 12
  • *
  • Posts: 85
  • Reputation: +3/-0
    • View Profile
javascript multiple form validation
« on: January 09, 2010, 10:27:17 AM »
I always hated javascript, but now i need it to validate forms.

Also I'm not quite an expert in expressing my self. So this will be long to desfirbe what i have, and what i need to accomplish.
I have forms generated by php.
As html source the page shows something like:

<form name='1'>
<input type ='text' onkeyup = "validate(1)" name='mynumber' />
</form>

<form name='1'>
<input type ='text' onkeyup = "validate(2)" name='mynumber' />
</form>

and i also have a javascript function:

<script type='text/javascript'>
function validate(formnumber) {

if (document.formnumber.mynumber.value = 1) {
    alert(whatever text);
   
}
}
</script>

well does not look exactly like this, but for the sake of problem description it should do it.
i need the same javascript to validate BOTH forms.
The javascript accepts 1 argument, that is always equal to the name of the form.

But then, why on earth does not it work?

I'm not 100% sure i managed to describe the problem properly.
But if I did, someone please tell what em i doing wrong, or hows this supposed to be done?


Offline codestryke

  • Administrator
  • Level 33
  • *****
  • Posts: 589
  • Reputation: +22/-0
    • View Profile
    • eXtremeCast Games
Re: javascript multiple form validation
« Reply #1 on: January 09, 2010, 10:53:27 AM »
Just change your function...

if( formnumber == 1 ) {
  alert('hello world');
}


Creating online addictions, one game at a time:

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal