LiamKeenan Posted March 11, 2013 Share Posted March 11, 2013 HTML FORM DATA <form id="" method="POST" onsubmit="return false;"> Name: <input type="radio" name="DoorFrame" id="DoorFrame" value="Door 1" onclick="sendRequest()" /> Name: <input type="radio" name="DoorFrame" id="DoorFrame" value="Door 2" onclick="sendRequest()" /> <input type="submit" value="submit" /> </form> <div id="show"></div> AJAX <script type="text/javascript" src="prototype.js"></script> <script> function sendRequest() { var DoorFrame = $('DoorFrame').value; new Ajax.Request("test.php", { method: 'POST', postBody: $("DoorFrame").serialize(), onComplete: showResponse }); } function showResponse(req){ $('show').innerHTML= req.responseText; } </script> PHP if (isset($_POST['DoorFrame'])) { echo "image here" . isset($_POST['DoorFrame']) ? "image here" . $_POST['DoorFrame'] : ''; } else { echo "EMPTY"; } The script is currently getting one value from the form but what I want to do is get both values depending on which one is chosen obviously but I also want to add another group of radio buttons and get the value selected from them as well. I am new to ajax but pretty good with php. Kind Regards, Quote Link to comment https://forums.phpfreaks.com/topic/275498-ajax-php-help/ Share on other sites More sharing options...
yomanny Posted March 12, 2013 Share Posted March 12, 2013 First, you shouldn't have the same ID on the two radio buttons, so change them to DoorFrame1 and DoorFrame2 or whatever. Then also send a parameter to the sendRequest() function: Name: <input type="radio" name="DoorFrame" id="DoorFrame1" value="Door 1" onclick="sendRequest(1)" /> Name: <input type="radio" name="DoorFrame" id="DoorFrame2" value="Door 2" onclick="sendRequest(2)" /> In the sendRequest() function, fetch the parameter and send this in the AJAX request instead, then in PHP you can see if it's 1 or 2, and use that to determine what to do. function sendRequest(door) { var DoorFrame = $('DoorFrame').value; new Ajax.Request("test.php", { method: 'POST', postBody: door.serialize(), onComplete: showResponse }); } I thinnnk that should work. - W Quote Link to comment https://forums.phpfreaks.com/topic/275498-ajax-php-help/#findComment-1418197 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.