Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Problems with trying to get the "text" of a drop down option

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #23422
    pghtech
    Member

    With some help from the community here, i was able to successfully get a jQuery function to grab the "val" of a selection of a drop down and do a conditional test with that value.

    However the problem with using the <option value=""> is that the value is dynamically created and can be any number. So I have to use the text between the <option value=""></option> which doesn’t ever change. However, I cannot successfully obtain that text (.text()).

    Details:
    – Drop down with: class="choice"
    – Drop down contains to options: "Someone Else" and "Me" as your two choices
    – By default the drop down has "Me" selected. I need to see when the drop down changes (.change(function()) if "Someone Else" was selected.

    NOTE: I have an alert ( ) there to return what is in the variable so I can see myself and it always returns blank.

    Here is my attempted code:

    Code:
    #50623
    pghtech
    Member

    Ok, so I made the following change and the variable "choice" now returns a value when the drop down selection changes. But the value of variable "choice" still doesn’t meet one of the two conditions ("Me" and "Someone Else"). The other oddity is that when I put in a "alert (choice)" to return the value it got it puts "Me" or "Someone Else" to the far right of the alert window.

    My changes

    Code:
    jQuery(“.choice”).change(function() {
    var choice = jQuery(“.choice option:selected”).text();
    alert (choice);
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘CSS’ is closed to new topics and replies.