input field and drop down select option

Javascript coding ..

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 34
Joined: Wed Jan 11, 2012 10:01 pm

Mon Jun 11, 2012 10:17 pm

i want the vice-versa of what the following code is giving output.... i.e. if the user types in the input
field then the drop down list related to that value should get updated...

if i type Mr. in input field the from drop down Mr. should get selected...
if typed Dr then from option Dr. should get selected..

Code: Select all

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(function() {
    // initialize the value of the input field to the selected value
    // of the dropdown list:

    $('#title').change(function() {
        // when the value of the dropdown list changes
        // update the input field

<select name="title" id="title">
  <option <a href="abstract.jpg">Mrs</a></option>
  <option value="Mr" >Mr</option>
  <option value="Miss" >Miss</option>
  <option value="Dr" >Dr</option>
  <input type="text" name="gtitle" id="gift_title" a href="" />

User avatar
New php-forum User
New php-forum User
Posts: 86
Joined: Mon Jun 04, 2012 10:05 pm
Location: Ankara, Turkey

Tue Jun 12, 2012 1:06 am

Try something like this:

Code: Select all

$('#gift_title').bind('change keyup',function(){
	var value = $(this).val();
	if(^Mrs\b/i) == 0) {
	else if(^Mr\b/i) == 0) {
	else if(^Dr\b/i) == 0) {
	else if(^Miss\b/i) == 0) {
Note: This script may have problems with names that start with "DR" like "DRaco Malfoy".

Post Reply