Hi I am trying to show 1.php on div firstresult and 1b.php to div secondresult. My code is not correct though. I want one option value to trigger two div and two php files. like to get the val and display 1.php to first and 1b.php to the second.
<script language='JavaScript'>
$(document).ready(function() {
$('#termid').change(function() {
var val = $(this).val();
$('#firstresult').load(val + '.php', { value: val }).$('#secondresult').load(val + 'b.php', { value: val });
});
});
</script>
<form>
开发者_高级运维 <select id="termid">
<option value="">- select -</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
</form>
<div id="firstresult"></div>
<div id="secondresult"></div>
You almost have it right - you just need to separate the two statements:
$('#firstresult').load(val + '.php', { value: val });
$('#secondresult').load(val + 'b.php', { value: val });
Something like this ? - actual loading will not work
$(document).ready(function() {
$('#termid').change(function() {
var val = $(this).val();
if(val==1){
$('#firstresult').load(val + '.php', { value: val });
}else if(val==2){
$('#secondresult').load(val + 'b.php', { value: val });
}
});
});
});
Considering using a switch-case statement if you plan on having multiple options.
精彩评论