Can I check if a button was pressed in node.js? - javascript

I'm trying to check if a button was pressed and then open a new html file, I'm using express.js app.get method to open all of my HTML files. So my question is how can I open a HTML file on the same window when I press a button?

You could but shouldnt. NodeJS is backend.
Also note, that NodeJS is no JavaScript as normally referred to.
It is written/programmed in JavaScript.
To do something on click you would need either a normal <a> tag if you just want to open a link or you use client-side JavaScript with an onlick handler to execute something after a user clicked on an element.

You can accomplish this using javascript embedded into the html like this:
<button onclick="window.location='http://google.com'">Click me</button>
you can also try window.open=url
please note that this isn't really using node, just javascript. this type of behavior belongs in the page.

I think this thread would help you :)
https://stackoverflow.com/a/33703429/4578393
it uses if statements to check if the button has been pressed
if(req.body.hasOwnProperty("butt1")){
console.log("butt1 clicked");
Taine

Related

Python requests: post JavaScript commands

I'm trying to get the content of a site, but this content only appears when I click the 'Chart' link, which is a JavaScript command like this:
javascript:__doPostBack('fcc1$dgrC$ctl02$ctl00',''
from a element like this:
Chart
This is the site:
And this is what happens when you click on 'Chart':
You can see that the link doesn't change, so the only way to get the chart code is by somehow send that JavaScript command
How to find all the chart links?
How can I do a 'virtual click' on the chart links?
And after that, how to get the new html?
I really appreciate your help!
doPostBack just sets the __EVENTTARGET and __EVENTARGUMENT form fields and submits the form. Those ''s are just quotes BTW.
If those links are indeed "clicked" by javascript listeners, you may have trouble finding a real link to click.
Instead, you could use a tool to simulate a web browser in python and "click" on that link to get to the next page. The best one I've used is Mechanical Soup: https://mechanicalsoup.readthedocs.io/en/stable/introduction.html.

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.

Using javascript/jquery to dial a number

Does anyone know how I can dial a number using javascript? I've tried the following:
window.location.href = 'tel:7178081998';
The button registers a click but doesn't do anything in the ios environment.
I'm running into an issue where my "tel" links do not work because of a script that I have (FastClick). I've tried everything I can think of which is why I am at where I am.
Thoughts?
555-867-5309 This should work.
If need put a pop up dialog to ask user " Are you sure you want to call" Just in case s/he clicked it unintentionally.
<a id="call" href="">555-867-5309</a>
Use call id to open a dialog, on click of ok, put data dynamically to href attribute.
Sounds like a sandbox issue. Why not break out of the restriction with an iframe? Dynamically add it to the DOM and have it dial the number.
Adding IFRAME to DOM by Javascript

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.

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