943,580 Members | Top Members by Rank

Ad:
Aug 10th, 2009
0

something about radiobutton on JavaScript

Expand Post »
I want reset user choice of radiobutton here is my code


javascript Syntax (Toggle Plain Text)
  1. form action="mailto:meerovichsergey@gmail.com" method="post" enctype="text/plain">
  2. <fieldset>
  3. <legend>Your opinion</legend>
  4. <input type="radio" name="choice" id="op1" value="All was perfect ,answer to all question." >&nbsp All was perfect ,answer to all question.<br/>
  5. <input type="radio" name="choice" id="op2" value="Arcticle is good,but there are a things to improve." >&nbsp Arcticle is good,but there are a things to improve.<br/>
  6. <input type="radio" name="choice" id="op3" value="Arcticle doesn't answer my questions" >&nbsp Arcticle doesn't answer my questions.<br/>
  7.  
  8. </fieldset>
  9. </form>
  10. <p align="center"><input type="submit" name="send2" value="Send" onclick="Send()" title="Press to send information" onfocus="Show()" size="10">&nbsp&nbsp <input type="reset" name="reset2" value="Reset" onclick="Res()" title="Press to Reset information" size="10"/></p>
  11.  
  12.  
  13. <script type="text/javascript">
  14. function Res()
  15. {
  16. opinion.value="";
  17. document.getElementById("op1").checked=false;
  18.  
  19. }
  20. </script>
  21.  



but in some reason it doesn't wotk ,what is wrong with it?
Last edited by peter_budo; Aug 11th, 2009 at 2:17 pm. Reason: If you want syntax hightlight use [code=javascript][/code] instead of [code][/code]
Similar Threads
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
polo_coins is offline Offline
63 posts
since Oct 2008
Aug 11th, 2009
0

Re: something about radiobutton on JavaScript

Your function Res() is incorrect, firstly there is no element named "opinion", so the function is failing on the first line:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. opinion.value="";

Your code to "reset" the radio buttons is correct but you need to reset all of them, currently you are only resetting one
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. document.getElementById("op1").checked=false;
, for three radio buttons it is fine to do them individually, but if u have more it would be better to loop through the buttons and reset them.

Try this:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. document.getElementById("op1").checked=false;
  2. document.getElementById("op2").checked=false;
  3. document.getElementById("op3").checked=false;
Reputation Points: 36
Solved Threads: 57
Posting Whiz
Thirusha is offline Offline
355 posts
since Mar 2008
Aug 11th, 2009
0

Re: something about radiobutton on JavaScript

Here my script I tried now :
html Syntax (Toggle Plain Text)
  1. <script type="text/javascript"">
  2. function Reset()
  3. {
  4. opinion.value="what to improve insert your opinion";
  5. document.getElementById("op1").checked=false;
  6. document.getElementById("op2").checked=false;
  7. document.getElementById("op3").checked=false;
  8. }
  9. </script>



and this is a <body>


html Syntax (Toggle Plain Text)
  1. <form action="mailto:meerovichsergey@gmail.com" method="post" enctype="text/plain">
  2.  
  3. <fieldset>
  4.  
  5.  
  6. <legend>Your opinion</legend>
  7. <input type="radio" name="choice" id="op1" value="All was perfect ,answer to all question." >&nbsp All was perfect ,answer to all question.<br/>
  8. <input type="radio" name="choice" id="op2" value="Arcticle is good,but there are a things to improve." >&nbsp Arcticle is good,but there are a things to improve.<br/>
  9. <input type="radio" name="choice" id="op3" value="Arcticle doesn't answer my questions" >&nbsp Arcticle doesn't answer my questions.<br/>
  10.  
  11.  
  12.  
  13. </fieldset>
  14. </form >
  15.  
  16. <p align="center"><input type="text" id="opinion" onmouseover="Show()" value="what to improve insert your opinion" title="enter text about this arcticle" tabindex="1" maxlength="90"size="100"/>
  17. <p align="center"><input type="submit" name="send2" value="Send" onclick="Send()" title="Press to send information" onclick="Reset();" onfocus="Show()" size="10">&nbsp&nbsp <input type="reset" name="reset2" value="Reset" title="Press to Reset information" size="10"/></p>

bu it's still doesn't reset [COLOR="blue"]radiobuttons[/colors]
Last edited by peter_budo; Aug 11th, 2009 at 2:18 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
polo_coins is offline Offline
63 posts
since Oct 2008
Aug 11th, 2009
0

Re: something about radiobutton on JavaScript

my mistake you was right
It work perfect .
Thanks
Best Regards
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
polo_coins is offline Offline
63 posts
since Oct 2008
Aug 11th, 2009
0

Re: something about radiobutton on JavaScript

Hi polo,

im not sure, if this is what you intend to do, but this might help you out, to shorten the lines inside your code and as wel as making the code to work in other modes of browsers.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <?xml-stylesheet type="text/css" href="#css_level21" media="all"?>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  4. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  6. <head>
  7. <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  9. <meta http-equiv="Content-Style-Type" content="text/css" />
  10. <meta http-equiv="Content-Script-Type" content="text/javascript" />
  11. <title>www.daniweb.com :: DHTML / JavaScript / AJAX</title>
  12. <style id="css21" type="text/css" media="all">
  13. /* <![CDATA[ */
  14.  
  15. /* ]]> */
  16. </style>
  17. <script type="text/javascript">
  18. // <![CDATA[
  19.  
  20. onreset = ( function( e ) {
  21. var form;
  22. if ( "mailer" in document ) {
  23. form = mailer || document.mailer;
  24. } else {
  25. form = (( form = document.getElementById( "mailer")) ? form : mailer );
  26. } var e = e ? e : event;
  27. var t = e.target ? e.target : e.srcElement;
  28. var opinion;
  29. if ( t.id === "res" || t.name === "res" ) {
  30. (( opinion = document.getElement( "opinion" )) ? opinion : document.all["opinion"] ).value = "";
  31. var radios;
  32. for ( var x = 1; !!( radios = form[ String( "op" + x ) ] ); x++ ) {
  33. if ( radios.checked ) {
  34. radios.checked = 0;
  35. }
  36. }
  37. } return false;
  38. }
  39. // ]]>
  40. </script>
  41. </head>
  42. <body id="xhtml11">
  43. <div id="main">
  44. <form id="mailer" name="mailer" action="mailto:meerovichsergey@gmail.com" enctype="text/plain" method="post">
  45. <fieldset><legend>Your opinion</legend>
  46. <table id="table-one" frame="void" rules="none" cellpadding="8" cellspacing="4" summary="JavaScript :: Live Demo!">
  47. <tr>
  48. <td><div><b>1.</b>&nbsp;<input type="radio" id="op1" name="choice" value="All was perfect, answer to all question." />&nbsp;All was perfect, answer to all question.</div></td>
  49. </tr>
  50. <tr>
  51. <td><div><b>2.</b>&nbsp;<input type="radio" id="op2" name="choice" value="Article is good, but there are things to improve." />&nbsp;Article is good, but there are things to improve.</div></td>
  52. </tr>
  53. <tr>
  54. <td><div><b>3.</b>&nbsp;<input type="radio" id="op3" name="choice" value="Article doesn't answer my question." />&nbsp;Article doesn't answer my question.</div></td>
  55. </tr>
  56. <tr><td style="border-top : 2px solid; white-space: pre;"><input type="submit" value="- send -" /> <input id="res" name="res" type="reset" value="- reset -" /></td></tr>
  57. </table>
  58. </fieldset>
  59. </form>
  60. <div>
  61. <!-- if you want to clear the value on this field w/o using any script: simply include this inside the <form> tag above -->
  62. <input type="text" id="opinion" name="opinion" onfocus="Show();" value="What to improve insert your opinion" maxlength="90" size="100" /></div>
  63. </div>
  64. </body>
  65.  
  66. </html>
  67.  

-essential
Last edited by essential; Aug 11th, 2009 at 7:21 am.
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: script for change<tr bgcolor> by mouseover
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Question about build a simple "Forum" on JavaScript





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC