skyer2000 Posted March 2, 2007 Share Posted March 2, 2007 I have the following form to give out either the value 1 or 0 when clicked. <div id='ajaxDiv'> <form name='vote'> <input type="hidden" id="pictureid" value="<? echo $pictureid; ?>"> <input type="radio" id="vote" value="1" onClick="ajaxFunction()">Yes | <input type="radio" id="vote" value="0" onClick="ajaxFunction()">No </form> </div> When no is pressed, it still gives "vote" the value of 0. When I take out the yes and only "no" in the form, it gives the vote value of 0. The following is the AJAX -> <script language="javascript" type="text/javascript"> function ajaxFunction(){ var ajaxRequest; try{ ajaxRequest = new XMLHttpRequest(); } catch (e){ try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var pictureid = document.getElementById('pictureid').value; var vote = document.getElementById('vote').value; var queryString = "?pictureid=" + pictureid + "&vote=" + vote; ajaxRequest.open("GET", "ajaxmysql.php" + queryString, true); ajaxRequest.send(null); } </script> Any ideas to have the "yes" and "no" work together? Quote Link to comment Share on other sites More sharing options...
mainewoods Posted March 3, 2007 Share Posted March 3, 2007 You have two id's with the same value id="vote". You can't do that. Give each of your radio buttons a 'name' value and use the same name for related radio buttons. Then get the value this way in your ajax code: var vote = document.formname.radiobuttonname.value; Quote Link to comment Share on other sites More sharing options...
skyer2000 Posted March 4, 2007 Author Share Posted March 4, 2007 You have two id's with the same value id="vote". You can't do that. Give each of your radio buttons a 'name' value and use the same name for related radio buttons. Then get the value this way in your ajax code: var vote = document.formname.radiobuttonname.value; I switched the radio buttons to have name values and changed the name of the form to "voteform". Then I used this code: var vote = document.voteform.vote.value; This didn't work however. Is that the correct way to pull out the value of the associated "name" value? Quote Link to comment Share on other sites More sharing options...
mainewoods Posted March 4, 2007 Share Posted March 4, 2007 that should work. Here's a good page: http://www.w3schools.com/htmldom/prop_radio_value.asp Quote Link to comment Share on other sites More sharing options...
skyer2000 Posted March 5, 2007 Author Share Posted March 5, 2007 Still not working. It kept giving a "undefined" value for vote. Here is the code back to what gave the "1" value for both yes and no clicked. Can someone modify this to make it work? I really appreciate it. <html> <head> <script language="javascript" type="text/javascript"> function ajaxFunction(){ var ajaxRequest; try{ ajaxRequest = new XMLHttpRequest(); } catch (e){ try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxDiv'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var pictureid = document.getElementById('pictureid').value; var vote = document.getElementById('vote').value; var queryString = "?pictureid=" + pictureid + "&vote=" + vote; ajaxRequest.open("GET", "regvote.php" + queryString, true); ajaxRequest.send(null); } </script> </head> <div id='ajaxDiv'> <form name="voteform"> <input type="hidden" id="pictureid" value="<? echo $pictureid; ?>"> <input type="radio" id="vote" value="1" onClick="ajaxFunction()">Yes | <input type="radio" id="vote" value="0" onClick="ajaxFunction()">No </form> </div> Quote Link to comment Share on other sites More sharing options...
mainewoods Posted March 5, 2007 Share Posted March 5, 2007 you could try passing the value as a parameter: <input type="radio" id="vote" value="1" onClick="ajaxFunction(this.value)">Yes then change your function like this: function ajaxFunction(vote){ Quote Link to comment Share on other sites More sharing options...
skyer2000 Posted March 9, 2007 Author Share Posted March 9, 2007 you could try passing the value as a parameter: <input type="radio" id="vote" value="1" onClick="ajaxFunction(this.value)">Yes then change your function like this: function ajaxFunction(vote){ That still makes it that clicking "no" will pass the "1" value. Any other ideas? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.