Jump to content

validation function


sMall!Girl

Recommended Posts

<script language="javascript">function validation(){if (form.keyword.value == ""){alert("msg");form.keyword.focus();return (false);}}</script>i was trying to make filling the filed optional in case i filled other one but i couldn'tcan you plz help me

Link to comment
Share on other sites

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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...