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: lonestar23 is an unknown quantity at this point 
Solved Threads: 0
lonestar23 lonestar23 is offline Offline
Light Poster

Radio Button - AJAX - Problem with Passing Value

 
0
  #1
Sep 5th, 2008
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>
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 961
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 134
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Radio Button - AJAX - Problem with Passing Value

 
0
  #2
Sep 5th, 2008
How many radio buttons' do you have in your form?
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 40
Reputation: lonestar23 is an unknown quantity at this point 
Solved Threads: 0
lonestar23 lonestar23 is offline Offline
Light Poster

Re: Radio Button - AJAX - Problem with Passing Value

 
0
  #3
Sep 5th, 2008
I am using only two radio buttons. 1 for yes and 0 for no.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 961
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 134
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Radio Button - AJAX - Problem with Passing Value

 
0
  #4
Sep 5th, 2008
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 5:02 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 961
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 134
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Radio Button - AJAX - Problem with Passing Value

 
0
  #5
Sep 5th, 2008
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. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 961
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 134
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Radio Button - AJAX - Problem with Passing Value

 
0
  #6
Sep 5th, 2008
Another option!
  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>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 383
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 35
langsor langsor is offline Offline
Posting Whiz

Re: Radio Button - AJAX - Problem with Passing Value

 
0
  #7
Sep 6th, 2008
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>
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 961
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 134
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Radio Button - AJAX - Problem with Passing Value

 
0
  #8
Sep 6th, 2008
Updates!

  1. <html>
  2. <head>
  3. <title></title>
  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>
  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 4:18 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 3918 | Replies: 7
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC