DrRossi Posted December 1, 2012 Share Posted December 1, 2012 I am trying to get the radio's button value from the form to the javascript onclick function to my database. I define my $output in first.php then echo it in second.php. Here is my first.php $name = 100; $answer = "some text"; $output .= '<div id="'.$k.'"> <form id='.$f.' > <input type="radio" name='.$name.' value="yes" checked>Accurate <input type="radio" name='.$name.' value="no">Not Accurate <input type="button" id='.$j.' value="Submit" onclick="sendData(\''.$answer.'\','.$name.',)"> </form> </div>' ; $name++; My jquery function in second.php function sendData(feel, rID) { var accu = $("input[@name=rID]:checked").val(); $.get("test.php", { feeling: feel , accuracy: accu} ); } When I click my button nothing is submitted. If i manually define var accu to "YES" or something it works. So the problem must be on how to check if my radio button its checked and get its value. Link to comment https://forums.phpfreaks.com/topic/271458-how-to-get-the-value-of-my-button/ Share on other sites More sharing options...
trq Posted December 1, 2012 Share Posted December 1, 2012 Variables are not interpolated within quotes in Javascript. Link to comment https://forums.phpfreaks.com/topic/271458-how-to-get-the-value-of-my-button/#findComment-1396736 Share on other sites More sharing options...
DrRossi Posted December 2, 2012 Author Share Posted December 2, 2012 well i tried it without quotes, single quotes..... nothing worked. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/271458-how-to-get-the-value-of-my-button/#findComment-1396777 Share on other sites More sharing options...
trq Posted December 2, 2012 Share Posted December 2, 2012 What does chrome developer tool have to say about... $("input[name=" + rID + "]:checked"); Link to comment https://forums.phpfreaks.com/topic/271458-how-to-get-the-value-of-my-button/#findComment-1396779 Share on other sites More sharing options...
DrRossi Posted December 2, 2012 Author Share Posted December 2, 2012 what do you mean? Sorry I am new to php and javascript. $("input[name=" + rID + "]:checked"); is in my function. If i view the source code I can see my button's attributes... Link to comment https://forums.phpfreaks.com/topic/271458-how-to-get-the-value-of-my-button/#findComment-1396780 Share on other sites More sharing options...
trq Posted December 2, 2012 Share Posted December 2, 2012 If your developing Javascript you need to learn how to use the tools available to debug it. Firebug (for firefox) and Developer Tools (for chrome). Using these tools you can type your code into a console, and the console shows various data. Link to comment https://forums.phpfreaks.com/topic/271458-how-to-get-the-value-of-my-button/#findComment-1396792 Share on other sites More sharing options...
DrRossi Posted December 2, 2012 Author Share Posted December 2, 2012 Okay found it. well I never used the console before just the html button to check the source code. Thanks for that tip. When I just define the accu as a number or text or even as rID it will come up with the "POST test.php" and the parameters etc. But when i try $("input[name=" + rID + "]:checked"); it will not do the POST test.php Link to comment https://forums.phpfreaks.com/topic/271458-how-to-get-the-value-of-my-button/#findComment-1396806 Share on other sites More sharing options...
DrRossi Posted December 2, 2012 Author Share Posted December 2, 2012 error found when I click the button Syntax error, unrecognized expression: input[@name=510]:checked throw new Error( "Syntax error, unrecognized expression: " + msg ); By the way that error won't show up in chrome's firebug, but it comes up in firefox firebug. Link to comment https://forums.phpfreaks.com/topic/271458-how-to-get-the-value-of-my-button/#findComment-1396807 Share on other sites More sharing options...
DrRossi Posted December 2, 2012 Author Share Posted December 2, 2012 anyone? Link to comment https://forums.phpfreaks.com/topic/271458-how-to-get-the-value-of-my-button/#findComment-1396949 Share on other sites More sharing options...
DrRossi Posted December 2, 2012 Author Share Posted December 2, 2012 OMG removed the "@" symbol and now it works smoothly! Thanks for your help!!! Link to comment https://forums.phpfreaks.com/topic/271458-how-to-get-the-value-of-my-button/#findComment-1396968 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.