473,320 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do we get this confirm box to reset the radio buttons when cancel is pressed?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Exam entry</title>
  4. <script language="javascript" type="text/javascript">
  5. function validateForm() {
  6. var result = true;
  7. var msg="";
  8. if (document.ExamEntry.name.value=="") {
  9. msg+="You must enter your name. \n";
  10. document.ExamEntry.name.focus();
  11. document.getElementById('name').style.color="red";
  12. result = false;
  13. }
  14. if (document.ExamEntry.subject.value=="") {
  15. msg+="You must enter the subject. \n";
  16. document.ExamEntry.subject.focus();
  17. document.getElementById('subject').style.color="red";
  18. result = false;
  19. }
  20. if ((document.ExamEntry.ExaminationNumber.value.length < 4) || (document.ExamEntry.ExaminationNumber.value.length > 4)) {
  21. msg+="You must enter your examination number. \n";
  22. document.ExamEntry.ExaminationNumber.focus();
  23. document.getElementById('ExaminationNumber').style.color="red";
  24. result = false;
  25. }
  26. if (!checkRadioArray(document.ExamEntry.level)) {
  27. msg+="You must select your level of entry. \n";
  28. document.getElementById('entry').style.color="red";
  29. result = false;
  30. }
  31.  
  32.  
  33. if(msg==""){
  34. return result;
  35. }
  36. {
  37. alert(msg)
  38. return result;
  39. }
  40. }
  41.  
  42.  
  43. function levelAlert(radio) {
  44. var level = radio.value;
  45. alert("You have selected " + level + " as your level of entry. \nIf this is not your level of entry press ok and choose another level.")
  46. }
  47.  
  48. function checkRadioArray(radioButtons) {
  49. for(var i=0;i < radioButtons.length; i++) {
  50. if (radioButtons[i].checked) {
  51. return true;
  52. }
  53. }
  54. return false;
  55. }
  56.  
  57. </script>
  58. </head>
  59. <body>
  60. <h1>Exam Entry Form</h1>
  61. <form name="ExamEntry" method="post" action="success.html">
  62. <table width="50%" border="0">
  63. <tr>
  64. <td id="name">Name</td>
  65. <td><input type="text" name="name" /></td>
  66. </tr>
  67. <tr>
  68. <td id="subject">Subject</td>
  69. <td><input type="text" name="subject" /></td>
  70. </tr>
  71. <tr>
  72. <td id="ExaminationNumber">Examination Number</td>
  73. <td><input type="text" name="ExaminationNumber" /></td>
  74. </tr>
  75.  
  76.  
  77.  
  78.  
  79. <tr>
  80. <td id="entry">Level of Entry</td>
  81. <td><input type="radio" name="level" value="A2"
  82. onclick="levelAlert(this)" />A2</td>
  83. </tr>
  84. <tr><td></td>
  85. <td><input type="radio" name="level" value="AS"
  86. onclick="levelAlert(this)" />AS</td>
  87. </tr>
  88. <tr><td></td>
  89. <td><input type="radio" name="level" value="GCSE"
  90. onclick="levelAlert(this)" />GCSE</td>
  91. </tr>
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98. <tr>
  99. <td><input type="submit" name="Submit" value="Submit" onclick="return validateForm();" /></td>
  100. <td><input type="reset" name="Reset" value="Reset" /></td>
  101. </tr>
  102. </table>
  103. </form>
  104. </body>
  105. </html>
Feb 17 '11 #1

✓ answered by acoder

Use return confirm(...) in place of the alert. Also add a return in the onclick.

1 5039
acoder
16,027 Expert Mod 8TB
Use return confirm(...) in place of the alert. Also add a return in the onclick.
Feb 17 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
0
by: sam | last post by:
I have 2 radio buttons on my form which are hidden. I need to have these radio buttons visible once a checkbox is selected. The radio buttons are hidden on loading of the form but I cannot make them...
3
by: Jay | last post by:
I noticed somewhere on the net that a post mentioned that there was a bug in the datagrid, radio buttons and a repeater. Something about the radio buttons are not mutually exclusive. (will this be...
3
by: Ken Varn | last post by:
This is probably a simple question, but I am new to this so bear with me. I have a ASP.NET form that has a checkbox and a 2 radio buttons. When the checkbox is checked, the 2 radio buttons are...
3
by: Ferret Face | last post by:
Hello, I have a web page that gets the user to select items from a list of options. This list is a set of independant Radio Buttons. I did not use a Radio Button List because I wanted the...
6
by: Advo | last post by:
Hi there. Having a few issues and cannot see a way to actually do the following. ive duplicated a simple questionnaire as shown here: http://www.hackeradio.com/questionnaire.html meaning...
2
nehashri
by: nehashri | last post by:
hello can any one please tell how to navigate or redirect radio buttons in a asp page to another asp page by vb script... i have four radio buttons when one of the them is choosen and submit...
3
by: sumanbangladesh | last post by:
Hi I have a page with 3 radio butons. If I select a specific one,then I like to view some other radio buttons otherwise the other radio buttons will be remain disabled or invisible. I am very...
7
by: gengyue | last post by:
Hi, I am running a report using Cold Fusion. This report is generated by cfloop tag. Depends on the record count of a query, the report will list the data retrieved from the database. each row in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.