-1

Hello I am trying to get a value from an HTML option tag but i'm getting the next error:

function get_states(){
    $(function(){
        $.ajax({
            **var id = $(this).val;** it says that the error is here but I don't see it
            url: 'competitors/get_states.php',
            method: 'post',
            contentType: "application/json",
            data: {id = id}
        }).done(function(msg){
            alert(msg);
        }).fail(function(msg, TxtStatus){
            alert("fallo: "+ TxtStatus);
        });     
    });
};

Hope you can help me, have a nice day.

2
  • And what is the next error?? Commented Apr 22, 2018 at 0:43
  • 3
    val is a method and not a property, so use var id = $(this).val(); Commented Apr 22, 2018 at 0:43

1 Answer 1

2
var id = $(this).val;

Should be

var id = $(this).val();

.val is a property, .val() is a method

To get the value of an element from jQuery, you need to use .val()

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

2 Comments

@RiggsFolly - Honestly didn't see your comment
I dont care, its my UV

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.