| | |
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:
Solved Threads: 0
I want reset user choice of radiobutton here is my code
but in some reason it doesn't wotk ,what is wrong with it?
javascript Syntax (Toggle Plain Text)
form action="mailto:meerovichsergey@gmail.com" method="post" enctype="text/plain"> <fieldset> <legend>Your opinion</legend> <input type="radio" name="choice" id="op1" value="All was perfect ,answer to all question." >  All was perfect ,answer to all question.<br/> <input type="radio" name="choice" id="op2" value="Arcticle is good,but there are a things to improve." >  Arcticle is good,but there are a things to improve.<br/> <input type="radio" name="choice" id="op3" value="Arcticle doesn't answer my questions" >  Arcticle doesn't answer my questions.<br/> </fieldset> </form> <p align="center"><input type="submit" name="send2" value="Send" onclick="Send()" title="Press to send information" onfocus="Show()" size="10">   <input type="reset" name="reset2" value="Reset" onclick="Res()" title="Press to Reset information" size="10"/></p> <script type="text/javascript"> function Res() { opinion.value=""; document.getElementById("op1").checked=false; } </script>
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]
Your function Res() is incorrect, firstly there is no element named "opinion", so the function is failing on the first line:
Your code to "reset" the radio buttons is correct but you need to reset all of them, currently you are only resetting one , 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)
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)
document.getElementById("op1").checked=false;
Try this:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
document.getElementById("op1").checked=false; document.getElementById("op2").checked=false; document.getElementById("op3").checked=false;
Life... Is a Moment
•
•
Join Date: Oct 2008
Posts: 63
Reputation:
Solved Threads: 0
Here my script I tried now :
and this is a <body>
bu it's still doesn't reset [COLOR="blue"]radiobuttons[/colors]
html Syntax (Toggle Plain Text)
<script type="text/javascript""> function Reset() { opinion.value="what to improve insert your opinion"; document.getElementById("op1").checked=false; document.getElementById("op2").checked=false; document.getElementById("op3").checked=false; } </script>
and this is a <body>
html Syntax (Toggle Plain Text)
<form action="mailto:meerovichsergey@gmail.com" method="post" enctype="text/plain"> <fieldset> <legend>Your opinion</legend> <input type="radio" name="choice" id="op1" value="All was perfect ,answer to all question." >  All was perfect ,answer to all question.<br/> <input type="radio" name="choice" id="op2" value="Arcticle is good,but there are a things to improve." >  Arcticle is good,but there are a things to improve.<br/> <input type="radio" name="choice" id="op3" value="Arcticle doesn't answer my questions" >  Arcticle doesn't answer my questions.<br/> </fieldset> </form > <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"/> <p align="center"><input type="submit" name="send2" value="Send" onclick="Send()" title="Press to send information" onclick="Reset();" onfocus="Show()" size="10">   <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.
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.
-essential
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)
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml-stylesheet type="text/css" href="#css_level21" media="all"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <title>www.daniweb.com :: DHTML / JavaScript / AJAX</title> <style id="css21" type="text/css" media="all"> /* <![CDATA[ */ /* ]]> */ </style> <script type="text/javascript"> // <![CDATA[ onreset = ( function( e ) { var form; if ( "mailer" in document ) { form = mailer || document.mailer; } else { form = (( form = document.getElementById( "mailer")) ? form : mailer ); } var e = e ? e : event; var t = e.target ? e.target : e.srcElement; var opinion; if ( t.id === "res" || t.name === "res" ) { (( opinion = document.getElement( "opinion" )) ? opinion : document.all["opinion"] ).value = ""; var radios; for ( var x = 1; !!( radios = form[ String( "op" + x ) ] ); x++ ) { if ( radios.checked ) { radios.checked = 0; } } } return false; } // ]]> </script> </head> <body id="xhtml11"> <div id="main"> <form id="mailer" name="mailer" action="mailto:meerovichsergey@gmail.com" enctype="text/plain" method="post"> <fieldset><legend>Your opinion</legend> <table id="table-one" frame="void" rules="none" cellpadding="8" cellspacing="4" summary="JavaScript :: Live Demo!"> <tr> <td><div><b>1.</b> <input type="radio" id="op1" name="choice" value="All was perfect, answer to all question." /> All was perfect, answer to all question.</div></td> </tr> <tr> <td><div><b>2.</b> <input type="radio" id="op2" name="choice" value="Article is good, but there are things to improve." /> Article is good, but there are things to improve.</div></td> </tr> <tr> <td><div><b>3.</b> <input type="radio" id="op3" name="choice" value="Article doesn't answer my question." /> Article doesn't answer my question.</div></td> </tr> <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> </table> </fieldset> </form> <div> <!-- if you want to clear the value on this field w/o using any script: simply include this inside the <form> tag above --> <input type="text" id="opinion" name="opinion" onfocus="Show();" value="What to improve insert your opinion" maxlength="90" size="100" /></div> </div> </body> </html>
-essential
Last edited by essential; Aug 11th, 2009 at 7:21 am.
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
![]() |
Similar Threads
- c# & asp.net radiobutton / dropdowlist questions (ASP.NET)
- HTML, CSS, JavaScript Developer (Web Development Job Offers)
- I need a little help with my button processing (javascript) (JavaScript / DHTML / AJAX)
- help needed in javascript (JavaScript / DHTML / AJAX)
- JavaScript / AJAX Guru (Software Development Job Offers)
- enabling a radiobutton in javascript (JavaScript / DHTML / AJAX)
- javascript for enabling and disabling (JavaScript / DHTML / AJAX)
- Are you a PHP and Javascript junkie? It's time you met Emma. (Software Development Job Offers)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: script for change<tr bgcolor> by mouseover
- Next Thread: Question about build a simple "Forum" on JavaScript
Views: 468 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxcode ajaxhelp animate api automatically beta boarder box bug button calendar card checkbox child class column cookies createrange() css cursor disablefirebug dom download dropdown editor element engine error events explorer ext file firehose flash form forms google gwt html htmlform ie8 iframe image() images internet java javascript jawascriptruntimeerror jquery jsf jsfile jump margin math matrixcaptcha microsoft mimic mp3 mysql object offline onmouseoutdivproblem onreadystatechange parent passing pdf php player post problem progressbar rated rating regex runtime scroll search select session shopping size sql star stars stretch text textarea twitter validation w3c web website window windowofwords windowsxp wysiwyg xml xspf \n





