2 peachy
05-19-2003, 03:56 PM
if I have a form, and in this form I have a checkbox called chkVerify, how do I write code to make sure that the box is indeed checked and if not check... give the user an alert telling them they need to check the box ?
|
Click to See Complete Forum and Search --> : Verify if a box is checked 2 peachy 05-19-2003, 03:56 PM if I have a form, and in this form I have a checkbox called chkVerify, how do I write code to make sure that the box is indeed checked and if not check... give the user an alert telling them they need to check the box ? Nevermore 05-19-2003, 03:59 PM if (document.yourformname.chkVerify.checked==true){//Your code here} 2 peachy 05-19-2003, 04:02 PM thankyou, does this also give the user an alert telling them they have to check the box if they didnt ? Nevermore 05-19-2003, 04:06 PM No, but this does: if document.yourformname.chkVerify.checked!=true) {alert("Please check the checkbox");} All you need to do is change the text yourformname to the name of your HTML form. 2 peachy 05-19-2003, 04:21 PM testing it... it still takes me to yahoo even if I dont check the box. what did I do wrong ? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script> if document.myForm.chkVerify.checked!=true) {alert("Please check the checkbox");} </script> </head> <body> <form action="http://www.yahoo.com" method=POST" name="myForm" id="myForm"> <input type="checkbox" name="chkVerify" value="1"> <input type="submit" name="action" value="Submit"> </form> </body> </html> AdamBrill 05-19-2003, 04:24 PM Try this instead:<html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script> function verify(){ if (document.myForm.chkVerify.checked!=true){ alert("Please check the checkbox"); return false; }else{ return true; } } </script> </head> <body> <form action="http://www.yahoo.com" method="POST" onsubmit="return verify();" name="myForm" id="myForm"> <input type="checkbox" name="chkVerify" value="1"> <input type="submit" name="action" value="Submit"> </form> </body> </html> 2 peachy 05-19-2003, 04:38 PM thankyou so much...smiles... feel like answering more questions ? I found a book and am trying different things in it. AdamBrill 05-19-2003, 05:17 PM Sure, go ahead and ask away. :) The best way to learn is to ask questions... ;) 2 peachy 05-19-2003, 05:25 PM I am reading about cookies. if I want to make my name be the cookie value, and I want to have the cookie expire in 30 days, but renew the 30 day expiration day each time I visit the page, how do I do this ? do I have to post a new thread because it is a new topic ... or can we just continue with this one ? AdamBrill 05-19-2003, 06:44 PM Ok, first of all, this question is fine in this thread, but you might as well post a new thread with unrelated questions. That way there aren't threads that have unrelated topics. ;) Anyway... You need to check if the cookie exist when someone comes to your site. If it doesn't exist, you set it, and if it does exist, you change the experation date to 30 days from the present. That is basically the method behind it... If you can't get it to work, let me know. ;) 2 peachy 05-19-2003, 06:47 PM I have done it five times and it doesnt work I just deleted it again starting over Jona 05-19-2003, 07:08 PM 2_peachy, I thought Dave went through the whole cookie thing with you... Post a new message nonetheless, though. lol Jona 2 peachy 05-19-2003, 07:13 PM yes, he did... and it was great, but, I guess I am a slow learner because I am still having trouble with it... that is why I am starting again, only with less information. maybe this time I will get it. Jona 05-19-2003, 07:37 PM You could reference back to what Dave Clark taught you. That should help you plenty. 2 peachy 05-19-2003, 07:47 PM I still have it... and will go back through it again... I have been doing that... it has so much information on it.... that it is hard for me to tell what editing I need to do to it to get it to do what I want it to... I have written it at least five times, and am certainly doing something wrong. he is a great teacher... it is me... it takes me a long time to learn some things.... and sometimes need to be shown again. I go over that code a lot.. just trying to understand what each part means. webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |