![](/img/trans.png)
[英]How to get the attribute value of an element using javascript onclick()?
[英]How to get Form Element Value using JavaScript
我试图在从父页面打开的弹出窗口中找到输入元素的值。
我的代码如下。 我无法从输入中获取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>
码:
<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)">
只需input
您的input
框id
<input id="1" name="details_<?=$pid?>" type="text"></input>
至
<input id="details_<?=$pid?>" name="details_<?=$pid?>" type="text"></input>
它应该工作
如果使用的是getElementById
,则必须使用pass来尝试获取其值的元素的id(在本例中为1)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.