Jump to content

validation function


Recommended Posts

I don't really get what you're trying to do. All fields are optional to begin with.If you're trying some other kind of validation try to explain what you're doing.Your current code is really primitive and doesn't look very useful to me.

Link to post
Share on other sites

So you have two fields that can be filled, but the user gets to choose which one? All you want to validate at this point is that ONE of them is filled in?

if ( (x.value == "") && (y.value == "") ) { // pull the trigger ONLY if both are empty	//alert. . .} else {	//submit}

Link to post
Share on other sites
So you have two fields that can be filled, but the user gets to choose which one? All you want to validate at this point is that ONE of them is filled in?
if ( (x.value == "") && (y.value == "") ) { // pull the trigger ONLY if both are empty	//alert. . .} else {	//submit}

This is what i want :) I am grateful because you spent some time to reply on my question thank you
Link to post
Share on other sites
So you have two fields that can be filled, but the user gets to choose which one? All you want to validate at this point is that ONE of them is filled in?
if ( (x.value == "") && (y.value == "") ) { // pull the trigger ONLY if both are empty	//alert. . .} else {	//submit}

sorry but it is not working>>>>>> i need more help>>
Link to post
Share on other sites

This should be in the onsubmit of the form:

<form action="" method="" onsubmit="return validation()">

Then, your JS should be:

function validate(){if((form.keyword.value == "")||(form.keyword.value==null)){alert("Empty"); //alerts that the value is emptyform.keyword.focus();return false;}elsereturn true;}

If that ain't help, could you show us your (complete) code :)

Link to post
Share on other sites
This should be in the onsubmit of the form:
<form action="" method="" onsubmit="return validation()">

Then, your JS should be:

function validate(){if((form.keyword.value == "")||(form.keyword.value==null)){alert("Empty"); //alerts that the value is emptyform.keyword.focus();return false;}elsereturn true;}

If that ain't help, could you show us your (complete) code :)

thanks dearas i said that i have two fileds and want give the user to fill one on themfunction validation(){if (form.x.value=="")or (form.y.value==""){alert("message");reurnt false;}elsereturn true;}it should be like this>>> plz correct it for me if it is including any mistake
Link to post
Share on other sites
thanks dearas i said that i have two fileds and want give the user to fill one on themfunction validation(){if (form.x.value=="")or (form.y.value==""){alert("message");reurnt false;}elsereturn true;}it should be like this>>> plz correct it for me if it is including any mistake
Erroenous. I did not looked any closer on the code earlier, but I realize you misseddocument.form.x.value in your code :) Note that x should be your form element's name.Also, this one is erroneous:
reurnt false
Anyway, here's a (complete) script for you to understand (better)
<script type="text/javascript">window.onload=function(){var df=document.forms[0];df[2].onclick=function(){if ((document.form.x.value=="")||(document.form.y.value=="")){alert("message");return false;}elsereturn true;}}	</script><form action="http://www.google.com" name="form"><input type="text" name="x"><input type="text" name="y"><input type="submit" value="submit"></form>

See if it helps :)

Link to post
Share on other sites
Erroenous. I did not looked any closer on the code earlier, but I realize you misseddocument.form.x.value in your code :mellow: Note that x should be your form element's name.Also, this one is erroneous:Anyway, here's a (complete) script for you to understand (better)
<script type="text/javascript">window.onload=function(){var df=document.forms[0];df[2].onclick=function(){if ((document.form.x.value=="")||(document.form.y.value=="")){alert("message");return false;}elsereturn true;}}	</script><form action="http://www.google.com" name="form"><input type="text" name="x"><input type="text" name="y"><input type="submit" value="submit"></form>

See if it helps :)

It is :) Thank you guysGod bless you
Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...