•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,609 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,615 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 704 | Replies: 6 | Solved
![]() |
•
•
Join Date: Jun 2008
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
I try alot of way but still cant the radio button to work. i need the user to select one of them else an error msg will appear.
I got the error msg to appear but it still load over to the next page as if i selected the gender.
Pls reply asap for a solution, need to complete it by next week. and can only start designing the background n stuff after all the field are correct thk.
I got the error msg to appear but it still load over to the next page as if i selected the gender.
<html>
<head><title> Kelvin's Guestbook </title>
<script language="Javascript">
function validate_length(field)
{
with(field)
{
if (value.length == 0)
{
alert("Pls Enter Your Name!"); return false;
}else return true;
}
}
function validate_email(field)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2)
{
alert("Not a valid e-mail address!"); return false;
}else return true;
}
}
function validate_gender(field)
{
with (field)
{
var male = document.getElementById("male");
var female = document.getElementById("female");
if (male.checked)
{
}
if (female.checked)
{
}
else
{
alert("Pls Select Your Gender");return false;
}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_length(yourname) == false)
{
yourname.focus(); return false;
}
if (validate_email(email)==false || validate_email(email)==false)
{
email.focus(); return false;
}
if (validate_gender(gender) == false)
{
gender.focus(); return false;
}
}
}
function startclock()
{
var thetime=new Date();
var nhours=thetime.getHours();
var nmins=thetime.getMinutes();
var nsecn=thetime.getSeconds();
var nday=thetime.getDay();
var nmonth=thetime.getMonth();
var ntoday=thetime.getDate();
var nyear=thetime.getYear();
var AorP=" ";
if (nhours>=12)
AorP="P.M.";
else
AorP="A.M.";
if (nhours>=13)
nhours-=12;
if (nhours==0)
nhours=12;
if (nsecn<10)
nsecn="0"+nsecn;
if (nmins<10)
nmins="0"+nmins;
if (nday==0)
nday="Sunday";
if (nday==1)
nday="Monday";
if (nday==2)
nday="Tuesday";
if (nday==3)
nday="Wednesday";
if (nday==4)
nday="Thursday";
if (nday==5)
nday="Friday";
if (nday==6)
nday="Saturday";
nmonth+=1;
if (nyear<=99)
nyear= "19"+nyear;
if ((nyear>99) && (nyear<2000))
nyear+=1900;
document.clockform.clockspot.value
=nhours+": "+nmins+": "+nsecn+" "+AorP+" "+nmonth+"/"+ntoday+"/"+nyear+","+nday;
setTimeout('startclock()',1000);
}
</script>
</head>
<body>
<FORM name="clockform">
Current Time: <INPUT TYPE="text" name="clockspot" size="32">
</FORM>
<SCRIPT language="JavaScript">
startclock();
</SCRIPT>
<Center>
<form name="guestbook" action="1.html"
onsubmit="return validate_form(this);" method="post">
<br>Name : <input type="text" name="yourname" value="">
<br>Email: <input type="text" name="email" size="30">
<br>Gender: <input type="radio" name="gender" value="Male" id="Male">Male
<input type="radio" name="gender" value="Female" id="Female">Female
<br>Comments: *Optional
<br><textarea cols="50" rows="8" name="Coments"></textarea>
<br><input type="submit" name="submit" value="Sign GuestBook">
<input type="Reset" name="Reset" value="Reset">
</form>
</Center>
</body>
</html> Last edited by Narue : Jun 26th, 2008 at 5:40 pm. Reason: Added code tags
•
•
Join Date: Aug 2006
Location: Noida, India
Posts: 152
Reputation:
Rep Power: 3
Solved Threads: 16
You know what makes ur life hell here.
Yes your Code itself. What the hell u have coded. No code tags.
As u r a new poster, I am solving ur problem.
Here is ur code that i modified (is this was ur code!!)
Now figure out what was wrong in ur code.
Yes your Code itself. What the hell u have coded. No code tags.
As u r a new poster, I am solving ur problem.
Here is ur code that i modified (is this was ur code!!)
html Syntax (Toggle Plain Text)
<html> <head><title> Kelvin's Guestbook </title> <script language="Javascript" type="text/javascript"> function validate_length(field) { with(field) { if (value.length == 0) { alert("Pls Enter Your Name!"); return false; }else return true; } } function validate_email(field) { with (field) { apos=value.indexOf("@"); dotpos=value.lastIndexOf("."); if (apos<1||dotpos-apos<2) { alert("Not a valid e-mail address!"); return false; }else return true; } } function validate_gender(gM, gF) { //alert("In"); //var male = document.getElementById("Male"); //var female = document.getElementById("Female"); if (gM.checked) { return true; } if (gF.checked) { return true; } alert("Pls Select Your Gender"); return false; } /**/ function validate_form(thisform) { with (thisform) { if (validate_length(yourname) == false) { yourname.focus(); return false; } if (validate_email(email)==false || validate_email(email)==false) { email.focus(); return false; } if (validate_gender(genderM, genderF) == false) { genderM.focus(); return false; } } } function startclock() { var thetime=new Date(); var nhours=thetime.getHours(); var nmins=thetime.getMinutes(); var nsecn=thetime.getSeconds(); var nday=thetime.getDay(); var nmonth=thetime.getMonth(); var ntoday=thetime.getDate(); var nyear=thetime.getYear(); var AorP=" "; if (nhours>=12) AorP="P.M."; else AorP="A.M."; if (nhours>=13) nhours-=12; if (nhours==0) nhours=12; if (nsecn<10) nsecn="0"+nsecn; if (nmins<10) nmins="0"+nmins; if (nday==0) nday="Sunday"; if (nday==1) nday="Monday"; if (nday==2) nday="Tuesday"; if (nday==3) nday="Wednesday"; if (nday==4) nday="Thursday"; if (nday==5) nday="Friday"; if (nday==6) nday="Saturday"; nmonth+=1; if (nyear<=99) nyear= "19"+nyear; if ((nyear>99) && (nyear<2000)) nyear+=1900; document.clockform.clockspot.value=nhours+": "+nmins+": "+nsecn+" "+AorP+" "+nmonth+"/"+ntoday+"/"+nyear+","+nday; setTimeout('startclock()',1000); } </script> </head> <body> <FORM name="clockform"> Current Time: <INPUT TYPE="text" name="clockspot" size="32"> </FORM> <SCRIPT language="JavaScript"> startclock(); </SCRIPT> <Center> <form name="guestbook" action="1.html"onsubmit="return validate_form(this);" method="post"> <br>Name : <input type="text" name="yourname" value=""> <br>Email: <input type="text" name="email" size="30"> <br>Gender: <input type="radio" name="genderM" value="Male" id="Male">Male <input type="radio" name="genderF" value="Female" id="Female">Female <br>Comments: *Optional <br><textarea cols="50" rows="8" name="Coments"></textarea> <br><input type="submit" name="submit" value="Sign GuestBook"> <input type="Reset" name="Reset" value="Reset"> </form> </Center> </body> </html>
Now figure out what was wrong in ur code.
Last edited by Luckychap : Jun 26th, 2008 at 4:17 pm.
When you think you have done a lot, then be ready for YOUR downfall.
•
•
Join Date: Aug 2006
Location: Noida, India
Posts: 152
Reputation:
Rep Power: 3
Solved Threads: 16
•
•
Join Date: Jun 2008
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
Still cant get the radio button to work, if i nv select it giv me the msg but still load to the page as if i select a choice. Can help see where i went wrong ??
thk's.
<html>
<head><title> Guestbook </title>
<style>
H1, H2, H3, H4, H5, H6 {color:#D4A017; text-align:center}
</style>
<script language="Javascript" type="text/javascript">
function validate_length(field)
{
with(field)
{
if (value.length == 0)
{
alert("Pls Enter Your Name!"); return false;
}else return true;
}
}
function validate_email(field)
{
with (field)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
if (apos<1||dotpos-apos<2)
{
alert("Not a valid e-mail address!"); return false;
}else return true;
}
}
function validate_gender(gender)
{
var genderChecked
for (var i=0; i<document.guestbk.gender.length; i++)
{
if (document.guestbk.gender[i].checked)
{
genderChecked = document.guestbk.gender[i].value
}
}
if(!genderChecked)
{
alert("Pls Select Your Gender")
}else return true;
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_length(yourname) == false)
{
yourname.focus(); return false;
}
if (validate_email(email) == false)
{
email.focus(); return false;
}
if (validate_gender(gender) == false)
{
gender.focus(); return false;
}
}
}
</script>
</head>
<body>
<h1>Welcome to my GuestBook</h1>
<Center>
<form name="guestbk" action="1.html" onsubmit="return validate_form(this);"
method="post">
<br>Name : <input type="text" name="yourname" value="">
<br>Email: <input type="text" name="email" size="30">
<br>Gender: <input type="radio" name="gender" value="Male">Male
<input type="radio" name="gender" value="Female">Female
<br>My Website Rating:
<select name="Number">
<option value="0"SELECTED>SELECT</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<br>Comments: *Optional
<br><textarea cols="50" rows="8" name="Coments"></textarea>
<br><input type="submit" name="submit" value="Sign GuestBook">
<input type="Reset" name="Reset" value="Reset">
</form>
</Center>
</body>
</html>thk's.
Last edited by ~s.o.s~ : Jun 28th, 2008 at 2:51 am. Reason: Added code tags, learn to use them.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- how I chang radio button selection ? (Visual Basic 4 / 5 / 6)
- Deselect the Radio Button (PHP)
- radio button (ASP.NET)
- Want to use radio button or menu bar instead of combo box (Java)
- Am not able to get a radio button selection to display in output (PHP)
- Security Settings -> Java permission -> Custom (radio button) -> Java Custom Settings (Web Browsers)
- Problem passing value from radio button to second page. (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: javascript and different versions of Java
- Next Thread: Pls help javascript tree view menus problem


Linear Mode