2013-05-20 33 views
0

我正试图从父页面打开的弹出窗口中查找输入元素的值。如何使用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> 
+2

您正在使用'getElementById'方法,但ID值等于1不等于“details_ ” –

+0

谢谢..感谢 –

回答

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)"> 
+0

非常感谢。 –

0

只是让你inputid

​​

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

它应该工作

0

如果您使用getElementById,你必须使用通过你正在试图获得来自值(在这种情况下,1)元素的ID。

相关问题