Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/196230-returning-a-value-to-a-php-variable/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.