EchoFool Posted June 8, 2008 Share Posted June 8, 2008 I am trying to put two values into a select box but I don't how to retrieve them. I have something like this: <option value="<?=$ItemID?>,Item"><?=$Name?> - Item</option> Then in the form process some how grab Item and grab <?=$ItemID?> value aswell. Is this possible ? Link to comment https://forums.phpfreaks.com/topic/109258-help-with-select-box/ Share on other sites More sharing options...
Buddski Posted June 8, 2008 Share Posted June 8, 2008 Need a little more information Are your trying to get the 2 values after Posting or before posting? Link to comment https://forums.phpfreaks.com/topic/109258-help-with-select-box/#findComment-560431 Share on other sites More sharing options...
pugboy Posted June 8, 2008 Share Posted June 8, 2008 PHP is server sided, so the posted form would not read the PHP code. I use the following below, which allows me to get all of my options from 2 text files, but you can modify it to fit your needs... $fileName = "../name.txt"; $fh = fopen($fileName, 'r'); $nameB = fread($fh, filesize($fileName)); fclose($fh); $name = explode("\n",$nameB); $fileName = "../var.txt"; $fh = fopen($fileName, 'r'); $varB = fread($fh, filesize($fileName)); fclose($fh); $var = explode("\n",$varB); for ( $id = 0; $id <= $maxid; $id += 1) { $indexfiletest = "../account/" . $user . "/" . $var[$id] . "/index.html"; if(!file_exists($indexfiletest)){ echo "<option value='$var[$id]'>$name[$id]</option>"; } } That will get the variable names from var.txt and the options from name.txt... I just echo the whole option tag inside of the select tag. Link to comment https://forums.phpfreaks.com/topic/109258-help-with-select-box/#findComment-560433 Share on other sites More sharing options...
EchoFool Posted June 8, 2008 Author Share Posted June 8, 2008 pugboy that looks over complicated for something that is probably simplistic to do. I am aware its server sided. I am trying to deal with process (after _POST and on submit) So value would come out as: 2,ITEM lets say in the form process. Then i need to break that apart to get just: $id = 2 $type = ITEM At that point i can then put them in to the correct fields in my database. Link to comment https://forums.phpfreaks.com/topic/109258-help-with-select-box/#findComment-560438 Share on other sites More sharing options...
Buddski Posted June 8, 2008 Share Posted June 8, 2008 After POSTING to a PHP page you can do $vars = explode(',',$_POST['variable']); $id = $vars[0]; $type = $vars[1]; You can also do simular with JS for the onSubmit if you are needing so. Link to comment https://forums.phpfreaks.com/topic/109258-help-with-select-box/#findComment-560441 Share on other sites More sharing options...
EchoFool Posted June 8, 2008 Author Share Posted June 8, 2008 After POSTING to a PHP page you can do $vars = explode(',',$_POST['variable']); $id = $vars[0]; $type = $vars[1]; You can also do simular with JS for the onSubmit if you are needing so. I shall give it a try. Thankyou. Link to comment https://forums.phpfreaks.com/topic/109258-help-with-select-box/#findComment-560444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.