I have this code:
<input type="text" name="frameSelection" id="frameSelection" value="Option 1" />
<a id="change">Change to Option 2</a>
When I click on the link I want to change the field value into “Option 2”. How can I do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Very simple. Use
clickto attach an event handler to theclickevent, andvalto set the value:As mentioned in other answers, you may want to prevent the default behaviour of the link, but with your code as it currently is in the question (with no
hrefattribute on theaelement) that’s not necessary. Just bear it in mind if that could change.