PDA

View Full Version : hidden key and checkbox



chxxqiqi
05-30-2007, 04:40 AM
lets say there are 2 forms, formA and formB.
formA holds a hidden key = '1'. (it may hold 1 or 2 or 3 or 4 or 5 only)
formA will send the value of the hidden key to formB.
formB has 5 checkbox. (checkbox1 - checkbox5)
if formB receive hidden key is '1', checkbox1 is checked while others is unchecked.

if formB receive hidden key is '3', checkbox3 is checked while others is unchecked.

how to perform this? thanks for helping...

mz241508
05-30-2007, 05:15 AM
What is it going to be used with, AMS, php, other please specify...

chxxqiqi
05-30-2007, 05:25 AM
What is it going to be used with, AMS, php, other please specify...

..........PHP..................

mz241508
05-30-2007, 05:48 AM
I'd suggest you took a look at this website - http://www.hotscripts.com/PHP/index.html

It has 13,241 php scripts. :)

Agent Jones
06-09-2007, 10:48 AM
Hello,

Are you doing this client-side or server-side?

Client-Side
Page is shown » Form A contains value "x" » Form A is submitted » Javascript is used to update Form B » Form B is submitted to your server

Server-Side
Page is shown » Form A contains value "x" » Form A is submitted to server » Server (PHP) shows another page with Form B » Form B is submitted again

If you're doing it Client-Side, you will have to create a Javascript function that handles the "onSubmit" event of Form A and then updates Form B according to Form A's values.

Doing it Server-Side is less tricky, at least for me. Just have a "switch" command on PHP:

<?php
$valuea = $_POST['hiddenkey'];

switch ($valuea)
{
case 1:
$checkbox1 = 'checked';
break;
case 2:
$checkbox2 = 'checked';
break;
[...]
default:
die('Invalid input...');
break;
}

for ($i = 0; $i <= 5; $i++)
{
echo("<input type='checkbox' name='checkbox$i' $checkbox" . $i . " />");
}
?>

This isn't the cleanest of the codes, but it should get you started... Good luck!