473,320 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Access selected value of a <select> field

Hi,

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
3 1677
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
chathura86
227 100+
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)

Regards
Chathura Bamunusinghe
Apr 11 '10 #3
@chathura86
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:
onchange="GetDropDownValue()"

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

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

Similar topics

1
by: Raghuram Banda | last post by:
Hi All, Can any one help me, how to get the selected value from <Select> tag using DOM I tried with document.getElementById("selectTagId").getAttribute("value") it's working fine with IE but...
1
by: Matthias Wege | last post by:
hello, is there any chance to shape borders of a <select>-field? i tried select { background-color:#eee; border:1px solid red; }
6
by: Bonge Boo! | last post by:
This has got to be obvious, but I can't make it work. I have a form called with 3 pull down menus. They are linked to a database which generates the values for the <SELECT? Pull-downs. Lets...
1
by: Davey | last post by:
How do I get the textual content of an <option> element within a <select> control? e.g. <select name='tc'><option value='0'>All</option><option value='1'>Some</option></select> Get the value...
2
by: Astra | last post by:
Hi All Wondered if you could help me with the below query. I have 1 simple table called STOCKCATS that consists of 2 fields. These fields are called CATID and LEVEL. The contents of this...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
4
by: VK | last post by:
I'm looking for autoexpand <select> list onfocus and collapse it back onselect/onblur (the list is select-one type) I know it is not possible directly, but I've seen here a hack by changing...
3
by: veg_all | last post by:
Say I have: <select> <option value='a' > First <option value='b' > Second <option value='c' > Third </select> Is there a way I can access the values First, Second and Third from an array ?...
1
by: ghadley_00 | last post by:
Hi, I have a php form that encodes the responses to various <Select> field drop down menus as numbers (e.g. 0 to 50), and then posts the data to a MySQL table. I am trying to implement a form...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.