繁体   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