问题描述:

I want to load a page on select on change event. But it aint displaying the page. the content on the page is just: this is bank/ this is cash.

<!DOCTYPE html>

<html>

<select id = "ddl" onchange="changeSheet()">

<option value = "bank">Bank Statement</option>

<option value = "cash">Cash Book</option>

</select>

<div id = "sheet">

</div>

<script>

function changeSheet()

{

document.getElementById('sheet').innerHTML = "";

var e = document.getElementById("ddl");

var strUser = e.options[e.selectedIndex].value;

if(strUser == 'bank')

{

$("#sheet").load("bank.php");

}

else

{

$("#sheet").load("cash.php");

}

}

</script>

网友答案:

This is the right way to do that using JQuery: DEMO

<!DOCTYPE html>
<html>
<select id = "ddl" onchange="changeSheet()">
    <option value = "bank">Bank Statement</option>
    <option value = "cash">Cash Book</option>
</select>

<div id = "sheet"></div>

<script>
$(document).ready(function(){
    $("#ddl").change(function(){
        if($(this).val() === "bank")
            $("#sheet").load("bank.php");    
        else 
            $("#sheet").load("cash.php");   
    });
});
</script>
相关阅读:
Top