php select change

Links for php scripts

Moderators: macek, egami, gesf

nepal12
New php-forum User
New php-forum User
Posts: 7
Joined: Tue Jan 03, 2012 11:35 am

php select change

Postby nepal12 » Mon Jan 09, 2012 5:41 am

Hi guys,
I need an urgent help from you profi .

Take a look at this:

<select name="cat">
<option id="opt1">Movie</option>
<option id="opt2">Music</option>
<option id="opt3">Television</option>

</select>

<select name="sub_cat">
<option id="s_opt1">Action </option>
<option id="s_opt2">Adventure</option>
<option id="s_opt3">Thriller</option>

</select>

The situation is so,

I select movie in first select option , then it should store a variable $catagory and i could be able to search the database to populate the options in second select. That is , the selection of the first one should store a variable which when check in the database can list the subcatagory with the catagory selected, in above case, when movie as cat is selected then the subcat should contain the options with category movie.

Thanks in advance

lonelygirl86
New php-forum User
New php-forum User
Posts: 14
Joined: Mon Jan 09, 2012 12:05 am

Re: php select change

Postby lonelygirl86 » Mon Jan 09, 2012 5:48 pm

That is simple to do, used in ajax.

In your first select box, put an onchange event that will call the ajax function.

Your first select box will look something like this

Code: Select all

<select name="cat" onchange="showsubcat(this.value);">
<option id="opt1" value="1">Movie</option>
<option id="opt2" value="2">Music</option>
<option id="opt3" value="3">Television</option>
</select>


showsubcat is you ajax function that will communicate with the database.

Hope that helps to you

nepal12
New php-forum User
New php-forum User
Posts: 7
Joined: Tue Jan 03, 2012 11:35 am

Re: php select change

Postby nepal12 » Tue Jan 10, 2012 12:55 am

thanks for your response, but could you please write some code , because I am very new to ajax and javascript.

lonelygirl86
New php-forum User
New php-forum User
Posts: 14
Joined: Mon Jan 09, 2012 12:05 am

Re: php select change

Postby lonelygirl86 » Wed Jan 11, 2012 5:25 pm



Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 2 guests

cron