mike2325 Posted March 23, 2010 Share Posted March 23, 2010 Hi, On my webpage I am currently able to bring up results from a sql database in a table. The results shown in a table correspond to a date entered by the user. Each row of the table has an ID and there is also a check box on each row of the table enabling the user to select that row in a booking process. Currently, I can get the ID to alert when the check box is clicked with this code: <td class="cell" align="center" height="19"><input type="radio" name="rad1" onclick="alert('.$row["id"].');" value="'.$row["id"].'"></td> . However, I need to get this row ID to be assigned to a variable so that it can be passed onto a different webpage using php sessions. I have tried returning the variable, assigning it, everything but I can't get my head round how to do this! It seems that if I can alert it correctly, it must be easy to assign the alerted value to a variable. Any suggestions would be really helpful! Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/196230-returning-a-value-to-a-php-variable/ Share on other sites More sharing options...
litebearer Posted March 23, 2010 Share Posted March 23, 2010 might try displaying your code again Quote Link to comment https://forums.phpfreaks.com/topic/196230-returning-a-value-to-a-php-variable/#findComment-1030503 Share on other sites More sharing options...
KevinM1 Posted March 23, 2010 Share Posted March 23, 2010 Remember, every page that you want to use sessions on requires that you have session_start at the beginning of your code. So, something like: session_start(); // code code code $_SESSION['rowId'] = $row['id']; In the other file: session_start(); $rowId = $_SESSION['rowId']; That said, I think your problem stems from some confusion over how PHP and JavaScript interact with each other. Quite simply, unless you're using AJAX, they don't. PHP can't automatically tell which checkbox is selected. Your PHP script is finished running once your page is displayed on the screen. JavaScript runs in the browser, which is why it can react to things like click events. You have two ways of sending the checkbox data to the other page - AJAX, which is probably more complicated than you want to get, or making your table a form and posting the values to the other page when the form is submitted. Quote Link to comment https://forums.phpfreaks.com/topic/196230-returning-a-value-to-a-php-variable/#findComment-1030507 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.