| | |
Radio Button - AJAX - Problem with Passing Value
Please support our JavaScript / DHTML / AJAX advertiser: 50% off 6 Months Dedicated Server Hosting from 1&1!
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 40
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 5: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: 383
Reputation:
Solved Threads: 35
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 4: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
Views: 3918 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
8 ajax ajaxcode ajaxexample ajaxhelp animate api array asp.net autocomplete autoplay box boxes bug cart content cookies css date db design display div dom download dynamic element embed error eventhandlers events explorer file firefox firehose flash focus font form function getselection google gxt hide html ie7 ie8 iframe image internet internet-explorer java javascript javascripthelp2020 javascripts jawascriptruntimeerror jquery js load maps matrixcaptcha media modal mysql objects onclick onmouseover parameters paypal php player position post realtimeprojects redirect reload repaeat resize reveal safari script scroll search select show simple size smarty sources sqlite stars string text textbox toggle upload variables web window xml





