Page 1 of 1

php form select option

Posted: Mon Jul 28, 2003 10:45 am
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

Hotscripts

Posted: Mon Jul 28, 2003 10:56 am
by teo
Can this Javascript from Hotscripts be what you are looking for?
http://www.hotscripts.com/Detailed/7976.html

Posted: Mon Jul 28, 2003 11:15 am
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.

Posted: Mon Jul 28, 2003 11:52 am
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.

Posted: Mon Jul 28, 2003 12:38 pm
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

Posted: Mon Jul 28, 2003 1:40 pm
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.

Posted: Mon Jul 28, 2003 1:56 pm
by jamrop
thanks very much for ur help

Posted: Mon Jul 28, 2003 3:00 pm
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

Posted: Mon Jul 28, 2003 4:30 pm
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.

Posted: Tue Jul 29, 2003 5:19 am
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

Posted: Sat Aug 09, 2003 4:53 am
by tylerdurden
Can you post the source of your current file? Let me have a look at it.