Page 1 of 1

Can I use value in a list as a "control" key...?

Posted: Tue Apr 13, 2004 1:32 am
by chinagirl
I have 2 fields in a table, Key and Description. I use a drop down list for keys (already dumped into an array), such as:
<?php
$list = "<SELECT NAME=\"$mylist\">";
$list .= "<OPTION VALUE=\"\">Select...</OPTION>";
for($i = 1; $i<n; $i++)
{
$list .= "<OPTION VALUE=\"$key[$i]\"";
$list .= ">$key[$i]</OPTION>";
}
$list .= "</SELECT>\n";
print $list;
?>

What I want to do next is to have an text editing box for ONE Description, depends on the key that is chosen from the above drop down list. Sounds simple, but I cannot get it to work right. Can anyone provide a code example? Thanks much.

Posted: Tue Apr 13, 2004 6:31 am
by JAM
Not possible usig PHP only, as when you/user selects something in the drop down box, everything that happens will occur at the client.

I'm moving this to the Client Side part of the forum. I bet the Java gurus can answer this. But do search the forum for an answer as I know this have been discussed before....

Posted: Wed Apr 14, 2004 8:25 am
by phait
hi,
this is possible as I have done it myself. I haven't got the time to write the code at present but I can tell you the theory and you can go from there until I get time.

Best way is to create a div to hold the textarea that you want to appear only if a certain key is chosen. Assign the div the CSS property of

Code: Select all

display: hidden;
then have an onchange event handler on your select menu that calls a javascript function.

The javascript function takes two parameters:
one is the id of the div and the other is the key to validate against. The function then checks the form element with the supplied id (the select menu in this case) and grabs the currently selected key. If the key is the same as the one supplied to the function in the onchange event handler then it sets the display property to

Code: Select all

display: block;
and hey presto it should appear ready to accept input. Remeber to place the textarea actually inside the hidden div block and that everything inside the div block will become visible once it is set to 'display: block'.

hth in the meantime.

not straight forward, but...

Posted: Tue Apr 20, 2004 8:29 pm
by chinagirl
I got my list work with javascript, though not dynamic enough, but should do. Thanks.