簡體   English   中英

如何使用JavaScript獲取表單元素值

[英]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您的inputid

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM