0
<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

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by diafol
0
<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>
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.