943,926 Members | Top Members by Rank

Ad:
Sep 5th, 2008
0

Radio Button - AJAX - Problem with Passing Value

Expand Post »
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
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2.  
  3. var settings = getXmlHttpRequestObject(); function saveCar() {
  4. if (settings.readyState == 4 || settings.readyState == 0) {
  5.  
  6. var car = escape(document.getElementById('car').value);
  7.  
  8. /* PROBLEM - Radio Button Processor */
  9. var proc17 = document.getElementById("search17");
  10. for (var i = 0; i < proc17.length; i++)
  11. {
  12. if (proc17[i].checked){
  13. search17 = proc17[i].value;
  14. break;
  15. }
  16. }
  17.  
  18.  
  19. settings.open("GET", 'abc.php?proc17=' + proc17 + '&car=' +car, true);
  20. settings.onreadystatechange = handleSettings; settings.send(null);}}
  21. function handleSettings() { if (settings.readyState == 4) {
  22.  
  23. }
  24. }
  25. </script>
Reputation Points: 20
Solved Threads: 0
Light Poster
lonestar23 is offline Offline
43 posts
since Mar 2008
Sep 5th, 2008
0

Re: Radio Button - AJAX - Problem with Passing Value

How many radio buttons' do you have in your form?
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Sep 5th, 2008
0

Re: Radio Button - AJAX - Problem with Passing Value

I am using only two radio buttons. 1 for yes and 0 for no.
Reputation Points: 20
Solved Threads: 0
Light Poster
lonestar23 is offline Offline
43 posts
since Mar 2008
Sep 5th, 2008
0

Re: Radio Button - AJAX - Problem with Passing Value

This was just an example u wil have 2 replace all the value to the specific name of your radio buttons

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var radioNames = [ 'radio1', 'search17' ];
  2. for (var i = 0; i <= 1; i++)
  3. {
  4. if (document.getElementById(radioNames).checked )
  5. { search17 = proc17.value; }
  6. }
but it would be nice if u can provide the exact name value of the two radio buttons.
Last edited by essential; Sep 5th, 2008 at 6:02 pm.
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Sep 5th, 2008
0

Re: Radio Button - AJAX - Problem with Passing Value

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)
  1. var radioNames = [ 'radio1', 'search17' ]; for (var i = 0; i <= 1; i++) {
  2. var proc17 = document.getElementById(radioNames[i]);
  3. if ( proc17.checked ) { search17 = proc17.value; }
  4. }
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Sep 5th, 2008
0

Re: Radio Button - AJAX - Problem with Passing Value

Another option!
javascript Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2.  
  3. function saveCar( e )
  4. { e = e ? e : window.event;
  5. t = e.target ? e.target : e.srcElement;
  6. // Things to do -->
  7.  
  8. if (( t.id ) && ( t.id == 'search17' ) && ( t.checked ))
  9. { search17 = t.value; }
  10.  
  11. }
  12. </script>
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Sep 6th, 2008
0

Re: Radio Button - AJAX - Problem with Passing Value

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?

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function i_am_ajax () {
  5. var form = document.getElementById("my_form");
  6. for ( var i = 0; i < form.length; i++ ) {
  7. if ( form[i].checked ){
  8. alert( form[i].value );
  9. break;
  10. }
  11. }
  12. };
  13. </script>
  14. </head>
  15. <body>
  16. <form id="my_form">
  17. <label><input type="radio" name="radio" value="0" />NO</label><br />
  18. <label><input type="radio" name="radio" value="1" />YES</label><br />
  19. <input type="button" onclick="i_am_ajax()" value="response" />
  20. </form>
  21. </body>
  22. </html>
Reputation Points: 30
Solved Threads: 36
Posting Whiz
langsor is offline Offline
389 posts
since Aug 2008
Sep 6th, 2008
0

Re: Radio Button - AJAX - Problem with Passing Value

Updates!

html Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <title></title>
javascript Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. <!--
  3. document.onclick = thisValue; function thisValue( e )
  4. { e = e ? e : window.event;
  5. f = e.target ? e.target : srcElement;
  6.  
  7. form1.txt1.value = f.value;
  8. f = f.name && f.name == 'r1' || f.name == 'b1' ? alert(f.value) : f;
  9. }
  10.  
  11. //-->
  12. </script>
html Syntax (Toggle Plain Text)
  1. </head>
  2. <form name="form1" action="#" onsubmit="return false;">
  3. <label for="id0">
  4. <input type="radio" value="sampleValue1" id="id0" name="r1" />&nbsp;Radio 1</label>
  5. <label for="id1">
  6. <input type="radio" value="sampleValue2" id="id1" name="r1" />&nbsp;Radio 2</label><br /><br />
  7. <input type="text" id="id2" name="txt1" />
  8. <input type="button" id="id3" name="b1" value="accept" accesskey="3" />
  9.  
  10. </form>
  11.  
  12. </body>
  13. </html>
Last edited by essential; Sep 6th, 2008 at 5:18 am.
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: how to figer out the page is rendered by the browser
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Frustrating Firefox Problem while making AJAX request on an anchor





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC