php form select option

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
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

php form select option

Post by jamrop »

I am trying to create a form. the first form is a select options that choses from 5 options. When i person selects one, another select option form opens with different options reference to the first form. Not sure how to do this. I know it would be if($submit)
{ if ($firstform == option1) { new select form }
if ($firstform == option 2 { new select form }

Not sure how to go around it and if it will work

Many thanks
teo
Forum Newbie
Posts: 5
Joined: Wed Jul 16, 2003 3:49 pm

Hotscripts

Post by teo »

Can this Javascript from Hotscripts be what you are looking for?
http://www.hotscripts.com/Detailed/7976.html
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Post by jamrop »

hey thanks for help

THe only problem is that i need the chosen option from the first form so i can add it to my database. from that javascript, the value is a web site, and i can not use that to put in my database.
tylerdurden
Forum Commoner
Posts: 66
Joined: Mon Jul 28, 2003 11:52 am
Location: Austria

Post by tylerdurden »

I've put up an example for you at http://www.titleofsite.com/foo.html Go check it out, it's quite simple. You can also easily create the required arrays with PHP.

Hmm. After re-reading your post I'm not sure if this will help you at all :-(

If you really want to go to a new page after the user selects an option you'll simply have to change a (hidden) form field to the value the user selected:

Code: Select all

var values = new Array();

valuesї1] = "Value1";
valuesї2] = "Value2";
valuesї3] = "Value3";
and in the leapto function add

Code: Select all

form.intodb.value = valuesїmyindex+1];
where intodb is the name of the hidden form field.
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Post by jamrop »

hey

thanks for that

i know u said it was simple but i am confused

So i want for select1 options For the family
For the garden
For the Home

I put them in the values as i want the chosen one to be inserted into database

Lets say, a user selects for the family
and in the select2 i would have For him
FOr her
For kids
For Babies
For Pets

, been trying to change it to them, but a bit confused

Sorry abuot this. Many thanks

Not that bothered about going to another page. This option looks the easiest way
tylerdurden
Forum Commoner
Posts: 66
Joined: Mon Jul 28, 2003 11:52 am
Location: Austria

Post by tylerdurden »

If you want to put "For the garden" into your db and not an associated value like "1" you'll have to use an associative array. Look at http://www.titleofsite.com/foo2.html.
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Post by jamrop »

thanks very much for ur help
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Post by jamrop »

hey

just been looking at ur code

on select 2 their is any one selection, but in ur arrays you have more than 1
tylerdurden
Forum Commoner
Posts: 66
Joined: Mon Jul 28, 2003 11:52 am
Location: Austria

Post by tylerdurden »

Yes, you need 1 array for the values and 1 for the labels. Since in your case label and value are the same you could also use

Code: Select all

myValuesї"For the family"] = new Array("FOr her","FOr kids","For babies","for pets")
and leave out the myLabels array,
and later in the function use:

Code: Select all

fld.optionsїi] = new Option(myValuesїst]їi]);
BTW: To prevent anyone from getting hurt I have to mention that I copied this code from some tutorial (who's URL I can't remember) and adapted it for my needs.
jamrop
Forum Commoner
Posts: 80
Joined: Fri May 16, 2003 5:38 pm

Post by jamrop »

hey

I still am a bit confused, actually well confused

You say drop mylabel values, but that is used in the functions.

i tried what u said, but still not working

many thanks
tylerdurden
Forum Commoner
Posts: 66
Joined: Mon Jul 28, 2003 11:52 am
Location: Austria

Post by tylerdurden »

Can you post the source of your current file? Let me have a look at it.
Post Reply