I want to enable or disable the buttons from page2.php
from page1.php
. when i click on the submit button from page1.php
it should ENABLE/DISABLE
button in the page2.php
without redirecting to page2.php
.
here am trying to send value from page1.php
to page2.php
using javascript. but unable to get data.
here is what i have tried.
page1.php
<html>
<head>
<script type="text/javascript">
function enable(){
var enable="enable";
window.location = "page2.php?temp=" + enable;
alert(enable);
}
</script>
</head>
<body>
click button to ebable or disable
<input type="submit" name="submit" id="submit" value="enable"onclick="enable();">
</body>
</html>
and this is my page2.php
<html>
<head>
<script type="text/javascript">
function enable(){
var temp=Request.querystring["temp"];
alert(temp);
}
</script>
</head>
<body>
click button to ebable or disable
<br>
<input type="submit" name="submit" id="submit" value="enable" onclick="enable()" >
</body>
</html>
can anyone suggest how to get it.?
答案 0 :(得分:0)
我认为你可以设置
var x = document.getElementById("button").setAttribute("value", "enable");
就像那样,您可以访问该特定变量并编辑它的能力。
使用javascript,您可以将按钮的能力值传递给第二个PHP页面。
答案 1 :(得分:0)
内部功能启用 获得临时值后
if(temp){
document.getElementById("myBtn").disabled = true;
} else {
document.getElementById("myBtn").disabled = false;
}
答案 2 :(得分:0)
试试这个:
注意:请阅读代码中的注释以获取更多说明。
page1.php 和 page2.php 将包含以下JS代码:
<script type="text/javascript">
function enable(){
// Set enable/disable in session to be read on next page and this page on refresh
var xhttp = new XMLHttpRequest();
xhttp.open("GET", "setButtonStatus.php", true);
xhttp.send();
// set enable/disable value for current event
if(this.value == 'enable'){
this.value = 'disable';
} else {
this.value = 'enable';
}
}
</script>
在 setButtonStatus.php
中<?php
// setButtonStatus.php
// Set button status as enable in session if not already set or if disabled
if(isset($_SESSION['setButtonStatus']) && $_SESSION['setButtonStatus'] == 'enable'){
$_SESSION['setButtonStatus'] = 'disable';
} else {
$_SESSION['setButtonStatus'] = 'enable';
}
?>
page1.php HTML代码
<input type="submit" name="submit" id="submit" value="<?php echo isset($_SESSION['setButtonStatus']) ? $_SESSION['setButtonStatus'] : 'enable' ; ?>" onclick="enable()" >
page2.php HTML代码
<input type="submit" name="submit" id="submit" disabled="<?php echo isset($_SESSION['setButtonStatus']) && $_SESSION['setButtonStatus'] == 'disabled' ? true : false ; ?>" value="<?php echo isset($_SESSION['setButtonStatus']) ? $_SESSION['setButtonStatus'] : 'enable' ; ?>" onclick="enable()" >
答案 3 :(得分:0)
更改您的代码,如下所示 page1.php中
<html>
<head>
<script type="text/javascript">
function enable(){
var enable="enable";
alert(enable);
window.location = "page2.php?temp=" + enable;
}
</script>
</head>
<body>
单击按钮以进行删除或禁用
page2.php
<html>
<head>
</head>
<body>
<style>
#submit{
display:none;
}
</style>
while page will load button is hide but if in url temp= enable then buton will be visible
<input type="button" value="button here" name="submit" id="submit" <?php if($_GET['temp']=='enable'){ echo "style='display:block'";} ?>>
</body>
</html>