0

http://medfor.petersenuploads.co.uk/product.php/698/2/clear-ps-honey-jar-with-metal-screw-cap

Click on the Full Price tab and 'ADD' one of the options. This should set the values of the select boxes below but it doesn't change. The event is firing correctly but not changing the selected items.

Could this be a data type issue?

$('a.addspecific').live(
    'click', function(e) {
        e.preventDefault();
        //console.log($(this).data('sterility'));
        console.log("IN");
        //Update dropdowns for JShop functionality
        $('#capacity').find("option").filter(function() {
            return $(this).text() == $(this).data('capacity');  
        }).attr('selected',true);
        console.log($(this).data('capacity'));
        $('#sterility').find("option").filter(function() {
            return $(this).text() == $(this).data('sterility');  
        }).attr('selected',true);
        console.log($(this).data('sterility'));
        $('#labeltype').find("option").filter(function() {
            return $(this).text() == $(this).data('labeltype');  
        }).attr('selected',true);
        console.log($(this).data('labeltype'));
        $('#itemspercase').find("option").filter(function() {
            return $(this).text() == $(this).data('itemspercase');  
        }).attr('selected',true);
        console.log($(this).data('itemspercase'));
        console.log("OUT");


    }
5
  • What exactly is it supposed to do ?? Commented Oct 19, 2012 at 16:18
  • 1
    @Sushanth-- When you click on an item's Add button, the menus in the Product Selection box should all change to match that item. Commented Oct 19, 2012 at 16:19
  • Click the 'ADD' button in the tabs and it should set the options at the bottom to the correct settings so if you click the 50ml|Sterile|No Label|314 option it changes the dropdowns appropriately. Commented Oct 19, 2012 at 16:19
  • Instead of matching the data to the text of an option, wouldn't it be simpler to match it to the option's value? Then you could do $("#capacity).val($(this).data('capacity')). Commented Oct 19, 2012 at 16:21
  • No. The value is not the same as the text. Commented Oct 19, 2012 at 16:25

2 Answers 2

4

The this context is fail, try it:

console.log("IN");
var thes = this;

$('#capacity').find("option").filter(function() {
     return $(this).text() == $(thes).data('capacity');  
}).attr('selected',true);
Sign up to request clarification or add additional context in comments.

Comments

0

Instead of

.attr('selected',true);

Try using

.prop('selected',true);

1 Comment

Doesn't seem to have any effect

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.