<form action="" method="get" name="form">

</form><select name="list1">
<option value="MUM">MUM</option>
<option value="DEL">DEL</option>
<option value="BAN">KOL</option>
<option value="HYD">HYD</option>
</select>
<select name="list2">
<option value="MUM">MUM</option>
<option value="DEL">DEL</option>
<option value="BAN">KOL</option>
<option value="HYD">HYD</option>
</select>
<input name="code" type="text" />

In above code there two list boxes .
I want to show ,if I select MUM from 1st list box and MUM from 2nd box then in text box there will be code like MUM-MUM-1.
Next time select MUM from 1st list box and DEL from 2nd list box then code will be
MUM-DEL-2.so on.

how i would to code to getting this output

Recommended Answers

All 2 Replies

<html>
<head>
<script lang='javascript'>


function setcode()
{
// alert( );
   document.form1.code.value = document.form1.list1.value+'-'+document.form1.list2.value+'-'+(document.form1.list2.selectedIndex+1);
}
</script>
</head>
<body>


<form action="" method="get" name="form1" >

<select name="list1" onchange=setcode()>
<option value="MUM">MUM</option>
<option value="DEL">DEL</option>
<option value="BAN">KOL</option>
<option value="HYD">HYD</option>
</select>
<select name="list2"  onchange=setcode()>
<option value="MUM">MUM</option>
<option value="DEL">DEL</option>
<option value="BAN">KOL</option>
<option value="HYD">HYD</option>
</select>
<input name="code" type="text" />
</form>
</body>
<script lang='javascript'>
setcode();
</script>
</html>
Member Avatar for diafol

What's the significance of the number at the end? Position of item in dropdown 2?

If you're using this to store data, why not use 2 fields and store just the items' ids?

<option value="1">MUM</option>

These should be taken from DB as opposed to being hard coded as changes to hard code will mess up values already stored.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.