Page 1 of 1

PHP array, html options!

Posted: Wed Oct 05, 2005 5:00 pm
by AndrewBacca
Hi,

I have a form that has a <Select> and options which are created from a database.

This is what it creates.

Code: Select all

<form onSubmit="" name="product_list" action="index.php?xps=pindex.php">
<select name="type">
<option selected value="null">Select a Product Type</option>
<optgroup label=Cat1>
<option value=3>Cat1Sub1</option>
</optgroup>
<optgroup label=Cat2>
<option value=5>SubCat1</option>
<option value=5>SubCat2</option>
</optgroup>
</select>
<br>
<input type="hidden" name="xps" value="pindex">
<input type="hidden" name="page_title" value="">
<input value="GO" type="submit" type="submit">
</form>
now when its submited to the other page I want it to set the "page_title" value not to the "value" of the option but the text inside the <options></options> tags.

I have trired creating an array in php at the same time that I populate the options and then adding

"this.page_title.value=" . $ptypearray[ . "this.type.value" . ]"

to the onsubmit bit but all I get is a php error which I know why!

There must be a way of doing this ?

Cheers

Andrew

P.s - Sorry if the post is a mess Im tired been working on this for a while!!!! lol :D

Posted: Wed Oct 05, 2005 5:04 pm
by feyd
it's best (and safest) to reconstitute the name on the submission processing page, although with the values being the same, it'd be challenging to know which text to use.. I'd suggest you use unique values for each option.

Posted: Wed Oct 05, 2005 5:06 pm
by AndrewBacca
thx for the reply but youve lost me!

maybe if I read it in the morning I'll get it lol

Posted: Thu Oct 06, 2005 5:55 am
by ruchit
i'd recommend using javascript & a hidded field... then form onSubmit you can call this code

Code: Select all

this.hiddenField.value=this.cmbType.options[this.cmbType.selectedIndex].text;
pass the value of hiddenField to your variable.