简体   繁体   中英

HTML form with two input fields

i need your help. I have a HTML form with 2 input fields which uses java script function from the variables var1 and var2 to make variable var3 . This variable var3 is returned. In IE it works, but only in Compatibility View. Does anyone have an idea? Here is the code used:

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

Try your javascript like below I hope this will work for you

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

You have no element with id searchword. You shoould do next:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM