1
<form name="myForm">
   <input type="text" name="f['cart']]['product_name']"/>
</form>

How can I access textfield's value using javascript?

1
  • name on <form> is a legacy attribute that only exists for backwards compatibility with truly ancient browsers. Use id instead. Commented Jul 3, 2012 at 11:50

1 Answer 1

7

Get the form from the forms collection, then the input from said form's elements collection.

document.forms['myForm'].elements["f['cart']]['product_name']"]
Sign up to request clarification or add additional context in comments.

1 Comment

My apologies, the code I was testing was embedded in a CMS which was changing the form name at run time I found. It does work perfectly.

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.