5 Replies - 1793 Views - Last Post: 25 June 2013 - 05:09 AM

#1 NoRemorse   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 26-January 11

Can't get text from select list

Posted 25 June 2013 - 03:29 AM

<fieldset>
                <legend>Search for the product:</legend>
                <div class="control-group">
                    <label for="manufacturer" class="control-label" style="float:left; margin-right: 25px;font-size: 16px;font-weight: bold;">Manufacturer:</label>
                    <div class="controls">
                        <select id="manufacturer" style="color: black;">
                            <option>ASUS</option>
                            <option>HP</option>
                            <option>Lenovo</option>
                            <option>Acer</option>
                            <option>Packard Bell</option>
                        </select>
                    </div>
                </div>
            </fieldset>
            <input type="submit" class="btn btn-large btn-success" value="Search" id="searchBtn">

<script>
    val manufacturer;
    $('#searchBtn').click(function(){
        manufacturer = $('#manufacturer').children(':selected').text();
        console.log(manufacturer);
    });

</script>


I am trying to get the text of the selected item from the select list, but I do not get anything as a result...
Does anyone have an idea what is wrong?

Is This A Good Question/Topic? 0
  • +

Replies To: Can't get text from select list

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: Can't get text from select list

Posted 25 June 2013 - 03:51 AM

there is no need to make it that complicated.
manufacturer = $('#manufacturer').val();

Was This Post Helpful? 1
  • +
  • -

#3 NoRemorse   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 26-January 11

Re: Can't get text from select list

Posted 25 June 2013 - 04:40 AM

It still does not work. code now is:
<fieldset>
                <legend>Search for the product:</legend>
                <div class="control-group">
                    <label for="manufacturer" class="control-label" style="float:left; margin-right: 25px;font-size: 16px;font-weight: bold;">Manufacturer:</label>
                    <div class="controls">
                        <select id="manufacturer" style="color: black;">
                            <option>ASUS</option>
                            <option>HP</option>
                            <option>Lenovo</option>
                            <option>Acer</option>
                            <option>Packard Bell</option>
                        </select>
                    </div>
                </div>
            </fieldset>
            <input type="submit" class="btn btn-large btn-success" value="Search" id="searchBtn">

<script>
    val manufacturer;
    $('#searchBtn').click(function(){
        manufacturer = $('#manufacturer').val();
        console.log(manufacturer);
    });

</script>


Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: Can't get text from select list

Posted 25 June 2013 - 04:50 AM

you are aware that the search button is submitting the form?
Was This Post Helpful? 1
  • +
  • -

#5 NoRemorse   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 26-January 11

Re: Can't get text from select list

Posted 25 June 2013 - 05:06 AM

I changed the button to :

<button class="btn btn-large btn-primary"  id="searchBtn">Search</button>


But still nothing.
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: Can't get text from select list

Posted 25 June 2013 - 05:09 AM

because that’s still a submit button. (all button types default to submit)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1