MGames
MGames

Reputation: 1181

JQuery Code For Selecting Select Option & Clicking Button Not Working?

Hi I'm tring to select the Large size and click the button from a website. I have the html code in fiddle as well as the jquery code I tried. I've tried these (below), but it doesn't seem to be working. What did I do wrong?

This is for selecting the Large size:

 $('select[name="size"] option').filter(function () { return $(this).html() == "Large"; }).attr("selected",true);

This is for clicking the button:

$('#add-remove-buttons').find('.button').trigger('click'); 

Here is the fiddle for what I've tried:

http://jsfiddle.net/8RnBf/645/

-Thank you

Upvotes: 0

Views: 51

Answers (4)

Andriy
Andriy

Reputation: 15442

try this:

$('#size').val($('#size option').filter(function(ind, el) {
  return $(el).text() === 'Large';
}).val());

demo: http://jsfiddle.net/rLerzj08/

Upvotes: 0

Luminous_Dev
Luminous_Dev

Reputation: 614

SOLUTION: demo

Make sure that the DOM is ready before this can be executed

$('select#size').val(39304).find('option[value="39304"]').attr('selected','selected')

Upvotes: 1

Luminous_Dev
Luminous_Dev

Reputation: 614

jsfiddle

 $('#add-remove-buttons').find('.button').on('click',function(e){
  alert($('select[name="size"]').val());
 });

I have changed only the jQuery, If this is what you wanted to capture what was selected on dropdown list when clicked.

Upvotes: 1

Mehrad
Mehrad

Reputation: 1543

$('#size').change(function(){

    $( "#size option:selected" ).each(function() {
       console.log( $( this ).text() );
    });

})

Upvotes: 0

Related Questions