jeudi 26 mars 2015

Javascript form reset not working

I have a form field which autocompletes as well as a form which allows users to search for someone's name. My two javascript functions are:



function enable_submit()
{
document.getElementById("id_search").style.visibility = "visible";
document.getElementById("autocomplete-search").reset();
document.getElementById("txtHint").style.visibility = "hidden";
document.getElementById("results").style.visibility = "visible";
}
function disable_submit()
{
document.getElementById("id_search").style.visibility = "hidden";
document.getElementById("id_simplesearch").reset();
document.getElementById("txtHint").style.visibility = "visible";
document.getElementById("results").style.visibility = "hidden";
}


Form code:



<form action="" id="autocomplete-search">
<div class="simplesearch">
<label for="intesearch">Start typing a name</label>
<input type="text" onkeyup="showCustomer(this.value)" id="intesearch" onfocus="disable_submit()">
</div>
</form>
<form id="id_simplesearch" name="simplesearch" method="post" action="index.asp">
<div class="simplesearch"><label for="forename">Forename</label><input type="text" id="id_forename" name="forename" value="<% response.write varForename %>" onfocus="enable_submit()" /></div>

<div class="simplesearch"><label for="surname">Surname</label><input type="text" id="id_surname" name="surname" value="<% response.write varSurname %>"onfocus="enable_submit()" /></div>
<div class="simplesearch"><label for="unit">Unit/Team</label><input type="text" id="id_unit" name="unit" value="<% response.write varUnit %>" onfocus="enable_submit()" /></div>


<div class="simplesearch">
<input class="simplesearchsubmit" type="submit" id="id_search" name="search" value="Search" />
</form>
</div>


The problem I have is that, when the simplesearch form is not set, focussing on the autocomplete-form will reset the simplesearch form yet when I submit the simplesearch form to produce a list of results and then click into the autocomplete field won't clear the values from simplesearch. What am I doing wrong? I have already modified the code from GET to POST thinking that it may be a problem with the data being held in the query string


Aucun commentaire:

Enregistrer un commentaire