Autoclick a form input? - javascript

I am trying to create an adhoc code that save me pressing a repetitive button on a webpage, I opened F12 developer and tried using getElementbyID(..).click(); however didn't quite work, this is part extract of the button, I wonder if someone can advise what code I can use to automatically submit the button? Any help will be greatly appreicated. Best regards, Jon

what code I can use to automatically submit the button
If this is for a regular form post without AJAX then you can select the form then use submit().
E.g.
/*
* The variable myform is previously determined such as by `document.forms[0]`
* or a similar DOM selector method
*/
myform.submit();
If this is for a non-form button then use the click() method as suggested in the comments above. However, be aware that for this method there would have to be an Event Listener attached for the button to do anything of value.

Related

How can i submit a form in PDF by using Javascript?

Is it possible to reference a Form or a Button on a PDF using Javascript?
What I am trying to do is to write Javascript code that will submit a form, or if not that, click a Button of my choice that submits the form.
The problem I have here is that I don't know how to reference the button or the form in Javascript.
So is there a way to achieve this?
In Acrobat JavaScript, you can not execute "click a button" as an action.
Instead you execute whatever the MouseUp event of that button has assigned. If it is a function, execute the function, if it is some lines of JavaScript code, execute those lines.
In any case, you will need a trigger event. When you have specified it, the rest is straightforward.
I also strongly recommend to have a good look at the Acrobat JavaScript documentation.

Selecting the correct element to trigger form submit from within a function

I have several forms on a page. The forms are actually PayPal "add to cart" buttons. When a user clicks on a button, an alert box asks for their zip code. If the zip code in in the array of okZips, I want to programmatically follow the link through the submit button to the cart, but I just can't quite get the correct element to attach .submit() to.
$(this).add("div.check-zip").add("form:first").submit();//this submits the first form on the page
$(this).add("div.check-zip").add("form").submit();//this submits the last form on the page
$(event.target).add("form").submit();//this doesn't submit anything
$(myEvent).add("form").submit();//this submits the last form where myEvent is a global variable
The pen can be found here:
http://codepen.io/enielsen0001/pen/KwEbzz
How do I select the correct element to apply the .submit()? Am I going about this all the wrong way?
You are not going all the wrong way but it is definitely the baddest and dirtiest way. It seems like you don't know what you are doing. Your classes are messed up, you are mixing jQuery and plain js, you are using while and for. It seems like you have deliberately copy pasted code with no idea what it is. Please have atleast beginner's js/jQuery knowledge before posting questions.
However, here is the updated pen http://codepen.io/anon/pen/NPJJwJ.
You would need the actual form object for submit to work.
// myEvent is event itself not element
$(myEvent.target).parent("form").submit();
I have refactored stuffs involving while and for loops you used. Compare your code with updated code. Hope it helps:

about html input tag

I know almost nothing about html and javascript. So pardon me if this is a silly question.
For a html input tag like this:
<input name="search1$btnSearch" id="search1_btnSearch" style="background-color: white;" type="submit" value="search"/>
What's gonna happen when this button is clicked?
I looked in all the .js files that are referenced by the page that contains this input tag, but I did not find any code that responds to it.
So how can I locate the code that responds to this button's click event?
By the way, I think the web site that contains this input tag is built with asp.net, because the pages have a .asxp extension.
Thanks.
This will likely submit a form to search something on the site.
Check the form tag in the html to see what file is referenced.
<form action="form_action.asp">
The action references the file.
It is used to submit a form created with the help of form tags and input elements.
What's gonna happen when this button is clicked?
Since it is a submit button, in the absence of any JS that overrides the normal functionality, it will submit the form.
I looked in all the .js files that are referenced by the page that contains this input tag, but I did not find any code that responds to it.
There might still be some.
So how can I locate the code that responds to this button's click event?
If it exists, it will likely show up if you turn on profiling in your JS debugger (make sure it is configured not to reset when you leave the page (which submitting the form will do)).
It submits the form it is in. This is HTML default and doesn't need Javascript.
Without being able to see the .js files associated with the code it is impossible to tell. But there are a few possibilities.
There is no JS attached and it simply submits the form to the server for processing.
There is JS attached to the input element itself, in which case you would look for code like $('#search1_btnSearch').click(function(){...
There is JS attached to the onsubmit event of the form itself, in which case you would just look for submit event handlers.
You can dig deeper into this code yourself by downloading the Firebug plugin for Firefox which allows you to easily browse and manipulate HTML, JS, CSS, and more.
Most probably (IF THERE IS ANY javascript) the JS event is binded to "search1_btnSearch". Use ctrl + f and search for "search1_btnSearch".
BTW: Why do you think that there is javascript involved ? what happens?
The standard behaviour without javascript is to submit the form, in which this submit button is embedded.
Nothing as far as I see
May be it is attached with a form that has some action defined and a method also. So that will decide about the action.

Validating PDF form fields before printing

I have a fillable PDF form that I would like to validate before the user prints it out.
Here is my form:
http://www.pentco.com/orderforms/pentco_creditapp_v2011b.pdf
I've looked online for a simple solution and I think I've found it. It is here:
http://www.alqemy.com/Forms/RequiredFields.pdf
I've looked at its field and button properties, but for the life of me I cannot figure out how it works. There is one line of code attached to the button behaviour and that's it.
Can someone tell me what I'm missing to put the same validation function in this form into mine?
Pete
The validateFields() method (used on button's mouse up event) is defined at document level. With Acrobat select 'Edit All JavaScripts' menu item and you will see the code for this method. It can be reused very easy, you just have to set tooltips for all required fields and these tooltips must end with '*' (this is how the method determines if a field is required).
This worked perfect...thanks for pointing out where to find that JavaScript. If others are confused:
You need to be in form edit
Then you go to Advanced-->Document Processing-->Edit All Javascript...
You will find the Validation code there. You want to copy it and add it to your print button's Javascript

Watir does not trigger Jquery event handler

I am testing a JQuery Web application. I have a JQuery popup that I simply cannot get the submit button to fire in Watir. The same pattern is used thought the application.
I have verified the button exists and have tried click, fireEvent you name it and am out of methods to call.
Has anyone solved this?
Which do you want ?
A. Control cursor and click "submit"
or
B. Simula te click "submit"
A:need to use Autoit and control cursor and click ,but only for windows OS. B:execute the javascript that when clicking "submit".
If B case,there is two ways I used always.
1.execute that code in URL-bar.
ex.) #ie.link(:URL, 'javascript:<-CODE->;').click
or
Make like that module and use it by include in test case.
ex.) #ie.excute_script(<-CODE->)
module Watir
class IE
def execute_script(scriptCode)
WIN32OLE.codepage = WIN32OLE::CP_UTF8
window.execScript(scriptCode)
end
def window
WIN32OLE.codepage = WIN32OLE::CP_UTF8
ie.Document.parentWindow
end
end
Maybe...
I hope it help.
Sorry my poor english.
tknv/
In my case the solution was to use and index value of 1. JQuery creates a copy of the form and all the popup items have an index of 1. The 0 index controls are on the original form.
I just had the same problem. Ajax upload for jQuery demo is an example page. I want to upload a file using Upload button on the left hand side of the page.
When I click Upload button by hand, file upload pop up appears.
When I click the button with Watir, nothing happens.
Gary (accepted answer) helped me to find a solution:
browser.file_field(:index, 1).set "/path/to/file"

Categories