I am new in programming. I have a code in which i use Jquery on HTML select tag. I have two Select Tag
<div style="margin-top:10px; width:280px; float:left">
<select name="s_name" id="s_name">
<option value="shahzad">Muhammad Shahzad Saleem</option>
<option value="hanif">Muhammad Jhangeer Hanif</option>
<option value="rana">Rana Muhammad Nadeem</option>
</select>
<br>
<select name="s_designation">
<option value="coo">Chief Operating Officer</option>
<option value="uh">Unit Head</option>
</select>
</div>
On first Select tag i use Jquery
<script>
$(function() {
$('#s_name').on('change',function(){
if( $(this).val()=="rana"){
$("#rana").show()
}
else{
$("#rana").hide()
}
if( $(this).val()=="hanif"){
$("#hanif").show()
}
else{
$("#hanif").hide()
}
});});
</script>
This Jquery is working fine for the following code
<div id="rana" style="display:none; margin-left:350px; width:auto; float:left">
<input type="text" name="uh1" value="Muhammad Jhangeer Hanif"/>
</br>
<input type="text" name="uh1_designation" value="Unit Head"/>
</div>
<div id="hanif" style="display:none; margin-left:350px; width:auto; float:left">
<input type="text" name="uh2" value="Rana Muhammad Nadeem"/> <br/>
<input type="text" name="uh2_designation" value="Unit Head"/>
</div>
Now i want to use jquery on my second select tag. I want that when user change the value in select tag s_name
then it will make change automatically in second select tag s_designation
For example by defalut my select tag show s_name
is shahzad saleem
and against its designation s_designation
is cheif operating offecier. But i want when user click on s_name
Hanif
or rana
then against its designation s_designation
will automatically change Unit Head
.
How i can do it? please tell me, Which will work with my existing jquery as well