开发者

Simulate button click in a Webpage

i'm trying to code an application for Android that fills up a form in a webpage,submits it and parse results to show them. I'm using javascript to fill up the fields and then call the form's a开发者_开发知识库ction, but it doesn´t work. I have studied the web html code, but i believe it uses JSF to display and handle the form. Is there any way to simulate the submit button click just as if i press it physically? In case anyone want to take a peak in the code, web url is http://www.transportedecantabria.es. The fact is i'm not a big expert in web programming and i'm a bit lost :).Thx and sorry about my english

EDIT: I've also tried this: javascript:var elementToGet = "frmBusqueda:j_id29"; var form = document.forms["frmBusqueda"]; var button = form.elements[elementToGet]; button.click();

But it keeps reloading the web, not giving me the submit result


You should be able to call the click() method on the button object to fire it, though it would probably be better to call the submit() method on the form object.


This code made the trick:

javascript:var elementToGet = "frmBusqueda:j_id29"; var form = document.forms["frmBusqueda"]; var button = form.elements[elementToGet]; button.click();

Thx all for your help


You can use

document.forms

to retrieve the form elements within the current document.

If you want to submit the first form:

var firstForm = document.forms[0];
firstForm.submit();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜