0

So i am trying to get a value of a field using jquery and a variable but for some reason I can't get it to work:

    var col = field1;
    var val = $('select[name='+col+']').val();

For some reason this code is not working and I am not sure why. But when I remove the variable it works fine.

    var val = $('select[name=field1]').val();

This works fine. How do i pass a variable value into this equation? Thank you for any help.

1 Answer 1

1

It looks like you should have field1 in quotes (you want it to be a string correct?)

var col = 'field1'; // now it's a string, and it'll work the way it seems like you intended
Sign up to request clarification or add additional context in comments.

Comments

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.