2013-07-29 36 views
2

我想将多个输入字段传递给一个弹出页面。 这里是我做了什么:从多个输入字段传递值使用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不工作,因为弹出窗口不开放。如何将这两个字段的值传递给我的新弹出窗口?

+0

是'的getElementById( 'PID1')'是你自己的功能? – mohkhan

回答

1

在这里,你有问题:

var category = getElementById('pid1'); 

您需要通过将其替换:

var category = document.getElementById('pid1'); 

由于getElementById作品与document对象。

+0

当我使用时它的工作正常: 'var category = document.getElementById('pid1')。value;' – aki2all

0

您需要使用

document.getElementById 

此外,您将需要使用的价值,因为的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值做类似的事情 - 不知道为什么你将它传递给函数。

0

试试这个

<!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> 
0

的jQuery,

var pid1Val = $("#pid1").val(); 
var pid2Val = $("#pid2").val() 

为Javascript,

var pid1Val = document.getElementById('pid1'); 
var pid2Val = document.getElementById('pid2'); 
相关问题