lundi 1 décembre 2014

prototype function to stimulate an event -javascript


I need to pass an variable from html to a javascript function which POSTs a request to a website:


In template (tag-info.html):



<td>
<a id = "gbrowse" href="#" onclick="gbrowse('onclick','<% gene.feature.uniquename %>')">
<%= gene.feature.uniquename %>
</a>
</td>


In Javascript (TagInfoView.js)



TagInfoView.prototype.gbrowse = function(eventName,tc){
var method = "POST";
var path = [website_name];
var params = {"#search":tc};
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);

for (var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
}

document.body.appendChild(form);
form.submit();
};

$('#gbrowse').gbrowse('onclick',tc);


With this I get 'tc' not defined error. How do I make a better call to the function gbrowse to execute the POST request to a website?





Aucun commentaire:

Enregistrer un commentaire