2013-01-10 39 views
0

我需要你的帮助。我有一个HTML表单,其中有2个input字段,它们使用来自变量var1var2的java脚本函数来创建变量var3。返回该变量var3。 在IE中它可以工作,但只能在兼容性视图中使用。有人有想法吗? 下面是使用的代码:带两个输入字段的HTML表单

<script type="text/javascript"> 
function sucheingabe() {  
var val1 = document.getElementById("searchword-1").value; 
var val2 = document.getElementById("searchword-2").value; 
var val3 = (val1) + ('+') + (val2) 
// alert (val3); 
document.getElementById('searchword').value = val3; 
} 
</script> 

<form class="search" action="index.php" enctype="application/x-www-form-urlencoded"  method="post"> 
<table style="width: 80%;" border="0" cellspacing="0" cellpadding="0" bordercolor="#111111"> 
<tbody> 
<tr> 
<td width="5%"> </td> 
<td width="15%"> 
<div id="searchWhat"> 
<p class="topHeaders"><strong>Was</strong> <span style="font-size: xx-small;">(Jobtitel oder Firmenname)</span></p> 
<input id="searchword-1" class="inputbox" alt="&gt;" maxlength="45" name="searchword-1" size="40" type="text" /></div> 
</td> 
<td width="5%"> </td> 
<td width="15%"> 
<div id="searchWhere"> 
<p class="topHeaders"><strong>Wo</strong> <span style="font-size: xx-small;">(Ort oder Postleitzahl)</span></p> 
<input id="searchword-2" class="inputbox" alt="&gt;" maxlength="45" name="searchword-2" size="40" type="text" /></div> 
</td> 
<td width="4%"><input onclick="sucheingabe();" name="Search" src="images/suchbutton.png" type="image" /> <input name="searchword" type="hidden" /> <input name="searchphrase" type="hidden" value="any" /> <input name="option" type="hidden" value="com_search" /> <input name="areas[0]" type="hidden" value="seminar" /></td> 
</tr> 
</tbody> 
</table> 
</form> 

回答

0

试试你的JavaScript像下面我希望这会为你工作

<script type="text/javascript"> 
function sucheingabe() {  
var val1 = document.getElementById('<%= searchword-1.ClientID %>').value; 
var val2 = document.getElementById('<%= searchword-2.ClientID %>').value; 
var val3 = (val1) + ('+') + (val2) 
// alert (val3); 
document.getElementById('<%= searchword.ClientID %>').value = val3; 
} 
</script> 
+0

你是如何得到这个想法使用ASP.net? –

-1

你有ID搜索内容没有元素。 你应该做下一步:

<input name="searchword" id = "searchword" type="hidden" /> 
+0

你没有id searchword的元素...是的,它..完美。非常感谢:-) –

+0

有趣的是,正确的答案有负面率:)嘿) – CruorVult

相关问题