something about radiobutton on JavaScript

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Oct 2008
Posts: 63
Reputation: polo_coins is an unknown quantity at this point 
Solved Threads: 0
polo_coins polo_coins is offline Offline
Junior Poster in Training

something about radiobutton on JavaScript

 
0
  #1
Aug 10th, 2009
I want reset user choice of radiobutton here is my code


  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]
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 318
Reputation: Thirusha is an unknown quantity at this point 
Solved Threads: 51
Thirusha's Avatar
Thirusha Thirusha is offline Offline
Posting Whiz

Re: something about radiobutton on JavaScript

 
0
  #2
Aug 11th, 2009
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;
Life... Is a Moment
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 63
Reputation: polo_coins is an unknown quantity at this point 
Solved Threads: 0
polo_coins polo_coins is offline Offline
Junior Poster in Training

Re: something about radiobutton on JavaScript

 
0
  #3
Aug 11th, 2009
Here my script I tried now :
  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>


  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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 63
Reputation: polo_coins is an unknown quantity at this point 
Solved Threads: 0
polo_coins polo_coins is offline Offline
Junior Poster in Training

Re: something about radiobutton on JavaScript

 
0
  #4
Aug 11th, 2009
my mistake you was right
It work perfect .
Thanks
Best Regards
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: something about radiobutton on JavaScript

 
0
  #5
Aug 11th, 2009
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.
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum


Views: 465 | Replies: 4
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC