mardi 28 octobre 2014

html onsubmit doesn't start Javascript function


Vote count:

0




I have a form with a Javascript populated collection of cacheable items, and a text box that is an id that is entered by a user. I want on the form submit to redirect the user to the JSON response from the rest call. The rest URL works when I enter directly into the browser however transferring that to html and js is beating me. The form on submit does nothing when the submit is clicked.


My form -



<form id="query" action="get" onsubmit="return restLink();">
<td>
<select id="selectCacheableItemType">
<option>Select a Cacheable Item Type</option>
</select>
</td>
<td>
Cacheable item Id: <input type="text" id="cacheableId"><br>
</td>
</form>


The cacheable item type is populated here -



window.onload = function cacheItemType(){
var select = document.getElementById("selectCacheableItemType");
var options = ["1", "2", "3", "4", "5", "6","7"];
for(var i = 0; i < options.length; i++) {
var opt = options[i];
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
select.appendChild(el);
}
};


and the restLink() function is -



function restLink() {
cachetypename = document.getElementyId('selectCacheableItemType').getValue();
cacheid = document.getElementyId('cacheableId').getValue();
return window.location.href = "http://localhost:8080/rest/query/"+ cachetypename + "/" + cacheid;
}


Any help is much appreciated.



asked 1 min ago







html onsubmit doesn't start Javascript function

Aucun commentaire:

Enregistrer un commentaire