0

Let's say I have two forms with the same textbox input on both:

<form name="form1" id="form1">
<input type="text" name="phone_number">
<input type="submit" value="Submit">
</form>

<form name="form2" id="form2">
<input type="text" name="phone_number">
<input type="submit" value="Submit">
</form>

Using JQuery, I want to select the input value for phone_number from form2, using a variable in the selector to reference form2, eg:

The value 'form2' is represented as variable 'someform' (THIS DOESN'T WORK):

$("#" + someform input[name=phone_number]").val();

Thanks.

1
  • This is not a duplicate of my question. I knew how to use a variable in a selector, what I didn't know was how to select a form field when the form id is a variable. Commented Oct 2, 2016 at 13:20

1 Answer 1

3

I figured it out.

$('#'+someform).find('input[name=phone_number]').val();
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.