Select form

They have: 218 posts

Joined: Apr 2001

I want to add multiple attributes to options in a Select drop down list (name,ID etc) as the list is dynamically generated from rows in a database. I can add the name option no problem:

$l = "<FORM METHOD=POST ACTION='$linkProc'>";
$l .= "<SELECT NAME = '$listName'>";
 
  for ($i=0;$i<$numWins;$i++){
$curWin = mysql_fetch_array($getWin,MYSQL_ASSOC);
$l .= "<OPTION>" . $curWin[$loopType] . "</OPTION>";
         }
         $procAppend = $linkProc . "&" . $listName;
$l .= " name = 'tranForm' ONSUBMIT=\"dex=document.tranForm.ListBox.options.selectedIndex;";
$l .= " void(tWin=window.open('$procAppend='+dex+', 'Cntrl','width=300,height=300'));\")";
$l .= "</SELECT>";
$l .= "<br><INPUT TYPE=SUBMIT VALUE='SELECT'>";
$l .= "<INPUT TYPE=HIDDEN NAME=cb VALUE='$cb'>";
$l .= "</FORM>";
echo $l;
'

But I'd like each option to have a database ID value. This is easily done in actionscript, how about javascript?

Thanks,

TM

Busy's picture

He has: 6,151 posts

Joined: May 2001

just add
value=\" $idnumber \"
to your tag, the $idnumber being how ever the id is pulled from database, $curWin[$id] ?

They have: 218 posts

Joined: Apr 2001

Thanks. I had a really silly javascript/server side workaround previously...Busy, what's the javascript code for when a user selects an option, an action automatically takes place (without having to press submit)?

Thanks,

TM

Suzanne's picture

She has: 5,507 posts

Joined: Feb 2000

you can set the action in the form itself to submit without a go button -- or in the individual elements.

http://www.scriptomizers.com/javascript/dropdownmenu_generator may help you, it uses onchange.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.