![](/img/trans.png)
[英]copy Multiple values from multiple input fields into one input field using javascript?
[英]Passing values from multiple input fields to popup using javascript/jquery
我正在嘗試將多個輸入字段傳遞給彈出頁面。 這是我所做的:
<tr>
<th>Item Category</th>
<td><input type="text" name="object_category" disabled="disabled" id="pid1" />
</td>
<tr>
<th>Item Name</th>
<td><input type="text" name="object_name" disabled="disabled" id="pid2" />
<input type="button" id="item_name" name="choice" onClick="selectValue2('id2')" value="?"></td>
</tr>
通過從其他頁面返回其值來填充的值。
現在,我想使用javascript將id: pid1
和id: pid2
的值傳遞到新的彈出頁面。 這是我的selectValue2()
函數定義:
function selectValue2(pid2){
// open popup window and pass field id
var category = getElementById('pid1');
window.open("search_item.php?id=pid2&&cat="+category+""",'popuppage',
'width=600,toolbar=1,resizable=0,scrollbars=yes,height=400,top=100,left=100');
}
但是,由於彈出窗口未打開,因此selectValue2不起作用。 如何將這兩個字段的值傳遞給我的新彈出窗口?
這里有問題:
var category = getElementById('pid1');
您需要將其替換為:
var category = document.getElementById('pid1');
由於getElementById
可用於document
對象。
您需要使用
document.getElementById
此外,您將需要使用value,因為getElementById會獲取整個元素
您的代碼如下所示:
function selectValue2(pid2){
// open popup window and pass field id
var category = document.getElementById('pid1').value;
window.open("search_item.php?id=pid2&&cat=" + category + """,'popuppage',
'width=600,toolbar=1,resizable=0,scrollbars=yes,height=400,top=100,left=100');
}
您可以對第二個pid值執行類似的操作-不確定為什么將其傳遞給函數。
嘗試這個
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function selectValue2(){
// open popup window and pass field id
var category = document.getElementById('pid1').value;
var pid = document.getElementById('pid2').value;
window.open("test.php?id="+pid+"&cat="+category+"",'popuppage',
'width=600,toolbar=1,resizable=0,scrollbars=yes,height=400,top=100,left=100');
}
</script>
</head>
<body>
<tr>
<th>Item Category</th>
<td><input type="text" name="object_category" id="pid1" />
</td>
<tr>
<th>Item Name</th>
<td><input type="text" name="object_name" id="pid2" />
<input type="button" id="item_name" name="choice" onClick="selectValue2()" value="?"></td>
</tr>
</body>
</html>
對於Jquery,
var pid1Val = $("#pid1").val();
var pid2Val = $("#pid2").val()
對於Javascript,
var pid1Val = document.getElementById('pid1');
var pid2Val = document.getElementById('pid2');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.