1

My html something like:

<html>
    ...
    <select class="ra1" id="rate2620_"> ... </select>
    <select class="ra1" id="rate2621_"> ... </select>
    ...
</html>

I have a for that is generating me all the functions for every select like:

for (i=from; i> to; i--){
    var ii = i.toString(); // ii = 2621 or 2620 or ...
    $("#rate" + i + "_").live("change", {pos: ii} ,function(e){
        sendValue($(this).val(),e.data.pos);
    });
}

I want to change my code to a function that acts for class="ra1" Something like (not working) :

$('.ra1').live("change", function(e){

    var id = $(this).children(":selected").attr("id"); // get the id element
    id = id.replace(/\D/g,'');  // convert from id="rate2620_" to> id="2620"

    sendValue($(this).val(),id);
});

So {pos: ii} ii should be changed with id, but I really have no ideea how it works.

0

1 Answer 1

3

You are using wrong id selector. It should be:

var id = $(this).attr("id");//or this.id for pure JS

also live has been deprecated in jquery 1.7+. If you are using later versions then use jquery .on()

Sign up to request clarification or add additional context in comments.

2 Comments

this.id also do that and i would say it is better to use.
@Jai: yup. the idea was him being using wrong id selector. Thanks :)

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.