0

我试图在从父页面打开的弹出窗口中查找输入元素的值。

我的代码如下。我无法从输入中获取 pc 值。

<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> 
4

3 回答 3

1

代码:

<input id="1" name="details_<?=$pid?>" type="text"></input>
<input   type="Submit"  onsubmit="sendValue(this.value)"></input>

改成:

  <input id="details" type="text">
  <input type="button" value='Send...' onclick="sendValue(document.getElementById('details').value)">
于 2013-05-20T02:07:43.807 回答
0

把你的input盒子id

<input id="1" name="details_<?=$pid?>" type="text"></input>

<input id="details_<?=$pid?>" name="details_<?=$pid?>" type="text"></input>

它应该工作

于 2013-05-20T01:53:32.707 回答
0

如果您使用getElementById,则必须使用传递您尝试从中获取值的元素的 id(在本例中为 1)。

于 2013-05-20T02:54:31.860 回答