| |||||||
This is a discussion on Javascript help needed! within the Technical Help forums, part of the Off Topic category; Hi guys, I'm doing GCSE Computing and I am making a website. For our homework we have to make to ...
![]() |
| | Thread Tools |
| | #1 |
| iPod Nano 1GB Join Date: Nov 2010 Location: Yo Momma :P (Im SO Funny)
Posts: 73
![]() | Javascript help needed!Hi guys, I'm doing GCSE Computing and I am making a website. For our homework we have to make to radio buttons to select whether we are male or female then we have an alert box when clicking submit saying "You have chosen (male/female)" or if nothing is selected it needs to say " Please select your gender." Here is my code so far which does include some alerts but it isn't the same var things for radio box: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>FunnyFings.com</title> <script> function validateform() { var x=document.forms["myform"]["email"].value; var xlength=document.forms["myform"]["email"].value.length; var y=document.forms["myform"]["password"].value; var ylength=document.forms["myform"]["password"].value.length; if (x==null || x=="") { alert("Email Address must be filled out"); } if ((xlength<"5") || (xlength>"25")) { alert("Email Address must contain between 5 and 20 characters"); myform.fname.focus(); return (false); } if (y==null || y=="") { alert("Password must be filled out"); } if ((ylength<"3") || (ylength>"10")) { alert("Password must contain between 3 and 10 characters"); myform.fname.focus(); return (false); } } </script> </head> <body bgcolor="#FF9900" > <marquee BGcolor="#66FF00" direction="right"> <center> Welcome To FunnyFings.com </center> </marquee> <form name="myform"> <br /> Email Address <input type="text" name="email" /> <br /> <br /> Password: <input type="password" name="password" /> <br /> <br /> <input type="radio" name="sex" value="male" /> Male<br /> <input type="radio" name="sex" value="female" /> Female <br /> <br /> Favourite Colour: <select name="favourite colour"> <option value="orange">Orange</option> <option value="red">Red</option> <option value="green">Green</option> <option value="blue">Blue</option> </select> <br /> <br /> <input type="checkbox" name="check box"/> I have read the non-existent Terms and Conditions. <br /> <br /> <input type="button" name="button" value="Subscribe" onclick="validateform()"/> </form> </body> </html>
__________________ |
|
| | #2 |
| iPod 30gb Join Date: Aug 2009 Location: Widnes
Posts: 1,090
![]() | Just add a new variable Code: var g=document.forms["myform"]["sex"].value;
__________________ Totally Free iPad | McFlurry Ice Cream Van Everything I say reflects my own opinions and not that of any company. Last edited by cono1717; 31-10-11 at 09:08 PM.. |
|
![]() |
| Thread Tools | |
| |