| | |
Radio Button - AJAX - Problem with Passing Value
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 36
Reputation:
Solved Threads: 0
Hello,
I am having problems retrieving correct values from two radio buttons in my AJAX script below.
The radio button values are either a 1 or 0 and always produces 0 regardless of which button is selected.
Once in AJAX, I can not have the script retreive a 1 or 0. AJAX script produces "[object HTMLInputElement]" as the response. Not sure what is going wrong.
Thanks in Advance.
Diego
Help with Code Tags
I am having problems retrieving correct values from two radio buttons in my AJAX script below.
The radio button values are either a 1 or 0 and always produces 0 regardless of which button is selected.
Once in AJAX, I can not have the script retreive a 1 or 0. AJAX script produces "[object HTMLInputElement]" as the response. Not sure what is going wrong.
Thanks in Advance.
Diego
Help with Code Tags
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script type="text/javascript"> var settings = getXmlHttpRequestObject(); function saveCar() { if (settings.readyState == 4 || settings.readyState == 0) { var car = escape(document.getElementById('car').value); /* PROBLEM - Radio Button Processor */ var proc17 = document.getElementById("search17"); for (var i = 0; i < proc17.length; i++) { if (proc17[i].checked){ search17 = proc17[i].value; break; } } settings.open("GET", 'abc.php?proc17=' + proc17 + '&car=' +car, true); settings.onreadystatechange = handleSettings; settings.send(null);}} function handleSettings() { if (settings.readyState == 4) { } } </script>
This was just an example u wil have 2 replace all the value to the specific name of your radio buttons
but it would be nice if u can provide the exact name value of the two radio buttons.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var radioNames = [ 'radio1', 'search17' ]; for (var i = 0; i <= 1; i++) { if (document.getElementById(radioNames).checked ) { search17 = proc17.value; } }
Last edited by essential; Sep 5th, 2008 at 6:02 pm.
Sorry if am bein hasty on that 1! Lets assume that you have 2 radio buttons with different name values!
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var radioNames = [ 'radio1', 'search17' ]; for (var i = 0; i <= 1; i++) { var proc17 = document.getElementById(radioNames[i]); if ( proc17.checked ) { search17 = proc17.value; } }
Another option!
javascript Syntax (Toggle Plain Text)
<script type="text/javascript"> function saveCar( e ) { e = e ? e : window.event; t = e.target ? e.target : e.srcElement; // Things to do --> if (( t.id ) && ( t.id == 'search17' ) && ( t.checked )) { search17 = t.value; } } </script>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
I would like to help, but I guess I just don't understand what the real problem is ... my quickie write-up of you above code delivers both 1 and 0
What am I missing here?
What am I missing here?
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<html> <head> <script type="text/javascript"> function i_am_ajax () { var form = document.getElementById("my_form"); for ( var i = 0; i < form.length; i++ ) { if ( form[i].checked ){ alert( form[i].value ); break; } } }; </script> </head> <body> <form id="my_form"> <label><input type="radio" name="radio" value="0" />NO</label><br /> <label><input type="radio" name="radio" value="1" />YES</label><br /> <input type="button" onclick="i_am_ajax()" value="response" /> </form> </body> </html>
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
Updates!
html Syntax (Toggle Plain Text)
<html> <head> <title></title>
javascript Syntax (Toggle Plain Text)
<script type="text/javascript"> <!-- document.onclick = thisValue; function thisValue( e ) { e = e ? e : window.event; f = e.target ? e.target : srcElement; form1.txt1.value = f.value; f = f.name && f.name == 'r1' || f.name == 'b1' ? alert(f.value) : f; } //--> </script>
html Syntax (Toggle Plain Text)
</head> <form name="form1" action="#" onsubmit="return false;"> <label for="id0"> <input type="radio" value="sampleValue1" id="id0" name="r1" /> Radio 1</label> <label for="id1"> <input type="radio" value="sampleValue2" id="id1" name="r1" /> Radio 2</label><br /><br /> <input type="text" id="id2" name="txt1" /> <input type="button" id="id3" name="b1" value="accept" accesskey="3" /> </form> </body> </html>
Last edited by essential; Sep 6th, 2008 at 5:18 am.
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: how to figer out the page is rendered by the browser
- Next Thread: Frustrating Firefox Problem while making AJAX request on an anchor
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array browser bug captchaformproblem cart checkbox child class close codes createrange() css cursor date debugger decimal dependent design disablefirebug dom dropdown editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images index internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post problem programming progressbar prototype redirect runtime safari scale scriptlets scroll search security shopping size software toggle unicode w3c web wysiwyg \n





