Jump to content

najd

Members
  • Posts

    3
  • Joined

  • Last visited

najd's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. najd

    Form Validation

    Dear sbrownii,Thank you for the explanation. I,ve got the idea. The code anyway seems to be not working._______________________Dear Blue,Thank you very much for this sweet code. It is working all fine.Best regards,Najd
  2. najd

    Form Validation

    Yes, both work but indiviually . means if I put them in the same page, then just one function will work - which is below the other code.I want them to check both inputs, not just one.
  3. Hi,I have two functions to validate two inputs (name,email) in a form, the problem is that one function works, and the other doesnt work. What should I add to make them all work?!The first function: <script type="text/javascript">function validate_required(field,alerttxt){with (field){if (value==null||value=="") {alert(alerttxt);return false}else {return true}}}function validate_form(thisform){with (thisform){if (validate_required(fname,"Name must be filled out!")==false) {fname.focus();return false}}}</script> The second function: <script type="text/javascript">function validate_email(field,alerttxt){with (field){apos=value.indexOf("@")dotpos=value.lastIndexOf(".")if (apos<1||dotpos-apos<2) {alert(alerttxt);return false}else {return true}}}function validate_form(thisform){with (thisform){if (validate_email(email,"Not a valid e-mail address!")==false) {email.focus();return false}}}</script> Finally, the form: <form action="submitpage.htm" onsubmit="return validate_form(this)"method="post"><input type="text" name="fname" size="20"><input type="text" name="email" size="30"><input type="submit" value="Submit"></form> Note: The function which is appove the other is the one that doesnt work! means that if I but it below the other code it will work.
×
×
  • Create New...