PHP array, html options!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

PHP array, html options!

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
AndrewBacca
Forum Commoner
Posts: 62
Joined: Thu Jan 30, 2003 10:03 am
Location: Isle of Wight, UK

Post by AndrewBacca »

thx for the reply but youve lost me!

maybe if I read it in the morning I'll get it lol
ruchit
Forum Commoner
Posts: 53
Joined: Mon Sep 26, 2005 6:03 am

Post 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.
Post Reply