954,160 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

something about radiobutton on JavaScript

I want reset user choice of radiobutton here is my code

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."   >&nbsp 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." >&nbsp 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" >&nbsp 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">&nbsp&nbsp <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?

polo_coins
Junior Poster in Training
63 posts since Oct 2008
Reputation Points: 8
Solved Threads: 0
 

Your function Res() is incorrect, firstly there is no element named "opinion", so the function is failing on the first line:

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

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:

document.getElementById("op1").checked=false;
	  document.getElementById("op2").checked=false;
	  document.getElementById("op3").checked=false;
Thirusha
Posting Whiz
357 posts since Mar 2008
Reputation Points: 36
Solved Threads: 57
 

Here my script I tried now :

<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

<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."   >&nbsp 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." >&nbsp 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" >&nbsp 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">&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]

polo_coins
Junior Poster in Training
63 posts since Oct 2008
Reputation Points: 8
Solved Threads: 0
 

my mistake you was right
It work perfect .
Thanks
Best Regards

polo_coins
Junior Poster in Training
63 posts since Oct 2008
Reputation Points: 8
Solved Threads: 0
 

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.

<?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>&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>
</tr>
<tr>
<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>
</tr>
<tr>
<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>
</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

essential
Posting Shark
974 posts since Aug 2008
Reputation Points: 114
Solved Threads: 138
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You