sMall!Girl Posted May 21, 2008 Share Posted May 21, 2008 <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 More sharing options...
Ingolme Posted May 21, 2008 Share Posted May 21, 2008 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 More sharing options...
killboy Posted May 21, 2008 Share Posted May 21, 2008 What I can get analyzing the code, is that there's a field that must be filled. If it's not filled, an alert will appear with an error message. Link to comment Share on other sites More sharing options...
jeffman Posted May 21, 2008 Share Posted May 21, 2008 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 More sharing options...
sMall!Girl Posted May 22, 2008 Author Share Posted May 22, 2008 Your current code is really primitive and doesn't look very useful to me.Thanks Link to comment Share on other sites More sharing options...
sMall!Girl Posted May 22, 2008 Author Share Posted May 22, 2008 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 More sharing options...
sMall!Girl Posted May 22, 2008 Author Share Posted May 22, 2008 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 More sharing options...
rangana Posted May 22, 2008 Share Posted May 22, 2008 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 More sharing options...
sMall!Girl Posted May 22, 2008 Author Share Posted May 22, 2008 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 More sharing options...
rangana Posted May 22, 2008 Share Posted May 22, 2008 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 mistakeErroenous. 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 falseAnyway, 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 More sharing options...
sMall!Girl Posted May 25, 2008 Author Share Posted May 25, 2008 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: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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.