Get value from selected form_dropdown() |
[eluser]bondjp[/eluser]
Hi, I have a form_dropdown where the user selects one item and this dropdown box is populated from database fields. When the user selects an item how can i pass that value to a variable without submiting any form? Here's what i have which is the standard form_dropdowm(): Quote:echo form_dropdown('whychange', $why);
[eluser]dark_lord[/eluser]
Just to give you an idea: Code: <?php To be able to get the value of that particular form object, in my own way I used Javascript getElementbyId(), try to take a look at it on the http://www.w3schools.com/jsref/met_doc_g...ntbyid.asp
[eluser]bondjp[/eluser]
[quote author="WishBear*" date="1268860622"]Just to give you an idea: Code: <?php To be able to get the value of that particular form object, in my own way I used Javascript getElementbyId(), try to take a look at it on the http://www.w3schools.com/jsref/met_doc_g...ntbyid.asp[/quote] thanks. Can you be a bit more specific about $this->validation->CivilStatus and $this->validation->CivilStatus_error ? Sorry, i'm still newbie .
[eluser]dark_lord[/eluser]
Try to copy and paste the below code and see if this is what your requirement is... Code: <html>
[eluser]bondjp[/eluser]
Using the link you gave me i just did this: Code: [removed] Ok, when i select an item, a pop up window appears with ALL the items in the dropdown box and not the one i chose...
[eluser]dark_lord[/eluser]
can you try changing alert(x.value); to alert(x.selectedIndex); lets see if this works...
[eluser]bondjp[/eluser]
Ok tried and now gives me a number. like this: item1 item2 item3 item4 If i select item 4 it gives me the number 3... PS: Ok i got it it starts at 0... Now how can i use this variable in my php code?
[eluser]bondjp[/eluser]
[quote author="WishBear*" date="1268865245"]Workaround? alert(x.selectedIndex + 1);[/quote] Ok the value starts at 0 so no need to work around :)... Now how can i pass this value and use it in my php code?
[eluser]danmontgomery[/eluser]
You won't be able to pass this value directly to a PHP variable on the page, because by the time the page is rendered PHP has finished processing. If you're unsure about this, I'd suggest googling the difference between server-side and client-side programming. What you can do, however, is use javascript to interact with the page after it's loaded. You can do this by using javascript's onChange() functionality... Normally, I'd suggest using a framework like jQuery, but I'm not sure that would be helpful without first having a grasp on javascript. I'd suggest starting here, depending on what you want to do (show/hide fields, load content, load a url, etc) this can be relatively easy or rather complicated. |
Welcome Guest, Not a member yet? Register Sign In |