开发者

how to assign the html value to the php variable without post or get method

in my program i had a php value $test = 2 using this value i done some oper开发者_如何学运维ation for example: in my page i had a 2 block A and B and one select box. If the test value is A it enable the div A, if the value is B it hide div A and also i am able to show and hide the div using the select box onchange event. please check my sample code given below

$test = $_GET["id"];

<select name="hideme" id="hideme" onchange="enableme();">
<option value="A">Show</option>
<option value="B">Hide</option>
</select>

if($test == 'A') {
<div id="div1" name="div1">
xxxxxxxxxxxxx
</div>
} 

Js Function :

function enableme() {
if(document.getElementByID('hideme').value == "A") {
document.getElementById.style.display ="block";

} else {

document.getElementById.style.display ="none";

}
}

my issue is at fist time using the $test($_get) value it show the correct div but the on change event is not working because of , if condition. If i remove the if condition then it show div A even if the value of the $test is B. how could i handle both. Please Help me


Shouldn't your JS function be something like:

function enableme() {
    if(document.getElementByID('hideme').value == "A") {
        if (document.getElementById('div1'))
            document.getElementById('div1').style.display = "block";
    } else {
        if (document.getElementById('div1'))
            document.getElementById('div1').style.display = "none";
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜