I am trying to find value of the input element in a popup window which is being opened from a parent page.
My code is below. I am getting not able to get pc value from input.
<html>
<head>
<?
$pid=$_GET['pid'];
$cart_url = '../cart.php?action=add&p='.$pid;
echo $cart_url;
?>
</head>
<body>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function sendValue(val){
window.opener.document.getElementById('details_<?=$pid?>').value = val;
window.opener.location.href='<?php echo $cart_url; ?>&pc='.concat(val);
window.close();
window.location.reload();
}
</script>
<form name="selectform">
<label>Enter Price:</label>
<input id="1" name="details_<?=$pid?>" type="text"></input>
<input type="Submit" onsubmit="sendValue(this.value)"></input>
</form>
</body>
</html>
Code:
<input id="1" name="details_<?=$pid?>" type="text"></input>
<input type="Submit" onsubmit="sendValue(this.value)"></input>
Change to:
<input id="details" type="text">
<input type="button" value='Send...' onclick="sendValue(document.getElementById('details').value)">
Just make your input
box id
from
<input id="1" name="details_<?=$pid?>" type="text"></input>
to
<input id="details_<?=$pid?>" name="details_<?=$pid?>" type="text"></input>
It should work
如果使用的是getElementById
,则必须使用pass来尝试获取其值的元素的id(在本例中为1)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.