drop down list

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
littlecoder
Forum Commoner
Posts: 26
Joined: Fri Oct 17, 2008 4:36 am

drop down list

Post by littlecoder »

Hello friends,

Is there any way to get the value from a drop down list at the instant it is clicked and not
when the 'Submit' button is pressed ?

Thanks in advance...
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: drop down list

Post by requinix »

Heh. Just realized I said "button". I meant "dropdown".

JavaScript. One way or another.

Add an onclick event to the button to submit the form. All it does is save the user the terrible task of moving the mouse an inch and slightly depressing one of the buttons.
Last edited by requinix on Fri Oct 17, 2008 3:03 pm, edited 1 time in total.
littlecoder
Forum Commoner
Posts: 26
Joined: Fri Oct 17, 2008 4:36 am

Re: drop down list

Post by littlecoder »

Hi ,

Yes, but that would only get the value in the javascript vode..
Is it possible to get that value into a php variable?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: drop down list

Post by requinix »

littlecoder wrote:Hi ,

Yes, but that would only get the value in the javascript vode..
Is it possible to get that value into a php variable?
I wrote:JavaScript. One way or another.
Either the form gets submitted or you use something like AJAX.
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: drop down list

Post by papa »

littlecoder wrote:Hi ,

Yes, but that would only get the value in the javascript vode..
Is it possible to get that value into a php variable?
Not true. You pass the var as as post or get.

$_GET[], $_POST[]

I use this:
<select onchange='this.$form_name.submit()'>
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: drop down list

Post by VladSun »

papa wrote:I use this:
<select onchange='this.$form_name.submit()'>
According to HTML DOM standards, every form element has a form property - the owning form element. So, I would rewrite your code as:

Code: Select all

<select onchange='this.form.submit()'>
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: drop down list

Post by papa »

Oops,

That's actually how I use it. Copied it wrong from my function. :)

...
$onSubmit = "onchange='this.form.submit()' ";
return "<select ".$onSubmit.$formSelect;
...
littlecoder
Forum Commoner
Posts: 26
Joined: Fri Oct 17, 2008 4:36 am

Re: drop down list

Post by littlecoder »

Hi friends ,

Thank you...The 'this.form.submit()' worked...
saved me a lot of time...Thank you
Post Reply