By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,527 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,527 IT Pros & Developers. It's quick & easy.

Access selected value of a <select> field

P: 10

I am working on a recipe website for my family and I'm struggling with the following.

If I click on "Other" in my Ingredient drop-down field (which is coming from mysql) then I need to have the next text field become enabled, so I can add a new ingredient.

BUT, the first thing I need to know is, what was selected in this drop-down list, and I've tried for several days now with no success.

As of right now, I can't find out what the user selected. I don't want to post, or get anything. I want to know immediately after they click on the item which one it was.

Can this even be done?
Apr 9 '10 #1
Share this Question
Share on Google+
3 Replies

P: 10
I now know that I can not use PHP since I am not sending anything to the server. Don't know why I didn't realize that before... got lost in the forest I guess.
Apr 10 '10 #2

P: 227
well you cannot get to know what user selected without sending a message to server (as get or post)

for your case if you dont want to send the request to the server you can use JS or similar to do the operation after a user selected a value.

and if you need any server side operations also to be executed you can use
AJAX to send a request to server without reloading the page

as far as i know there are no other ways, (may some one else does)

Chathura Bamunusinghe
Apr 11 '10 #3

P: 10
Thank you for replying!

I didn't want to use the server to obtain the value selected. I ended up using js and it works just fine now. It looks like this in case anyone else has the same question.

In my select field I put:

my function is as follows:
Expand|Select|Wrap|Line Numbers
  1. // Get DropDown value and based on value enable next field
  2. function GetDropDownValue()
  3.        {
  4.      ingValue = document.frmAddIngredient.Ingredients.value;
  5.      //alert(ingValue);
  6.           if (ingValue == 27) {
  7.              document.frmAddIngredient.txtIngredient.disabled=false;
  8.         }
  9.         else {
  10.             document.frmAddIngredient.txtIngredient.disabled=true;
  11.         }
  12. }
I actually had to do a happy dance for a few minutes after struggling with this for a couple days. All because I wasn't standing back and looking at the big picture. Don't know why I wasn't thinking that php is server side and js is client side. Live and learn!
Apr 11 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.