Atom Vayalinkal
Atom Vayalinkal

Reputation: 2702

Changing option value based on text input

I have a form that has a dropdown menu i need the user to be able to change the value of the options in the dropdown menu by changing the value in the textbox, how would do this using jquery javascript or php?

<div id="formh">
<form id="form">
<select name="test" id="test">
<option id="op1" value="1">1234</option>
<option id="op2" value="2">2134</option>
</select>
</form>
</div>
<div id="st">
<form name="settings">
Op1 Value<input />
Op2 Value<input />
</form>
</div>

Upvotes: 1

Views: 1144

Answers (3)

TonyTheJet
TonyTheJet

Reputation: 527

You would definitely do this with JavaScript. The only question is whether you need to retrieve information from the server, in which case you would need to use an AJAX solution and get information back from the server. Otherwise, however, you are absolutely fine with just some simple JavaScript.

Upvotes: 1

Mark Coleman
Mark Coleman

Reputation: 40863

If i understand your question correctly it appears you want to change the value of an option from a text box.

If you give the input box an id, you could do the following:

$("#inputOpt1").change(function(){
  $("#op1").val($(this).val());
});

Example of this on jsfiddle.

Upvotes: 1

Rob Lee
Rob Lee

Reputation: 75

Mark is correct, you can also use the focusout() jquery function if you want the data to update when the use clicks out of the input box.

Upvotes: 1

Related Questions