[英]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.