clicking a button in javascript without button id or class - javascript

I'm trying to use AppleScript to click a button on a webpage, however the button I need to click doesn't have an ID or Class, and it's located inside a div/input tag:
<div style="margin:0;padding:0;position:absolute;width:100px;right:20px"><input style="padding:4px;height:2em;width:100px" type="submit" value="save" tabindex="-1"></div>
<input style="padding:4px;height:2em;width:100px" type="submit" value="save" tabindex="-1">
I tried using querySelector, but it didn't work. How do I go about clicking this button?

In this case an attribute selector would work fine, I'd imagine.
document.querySelector('input[value="save"]')
More information from MDN: https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors

Related

Error clicking button in form with Jaunt

So I am trying to submit a form using Jaunt. There are two submit buttons, a check and apply. I am Trying to click the check button but am having some trouble because it cant find the button with the identifier of "check".
I am basically copying what is done on the Jaunt tutorial #15,
http://jaunt-api.com/jaunt-tutorial.htm
I have tried the value of the button as well but to no luck
Code:
form.submit("Check");
Html:
<input name="action" class="a-button-input" type="submit" value="checkValue" aria-labelledby="gc-redemption-check-value-announce">
<span id="gc-redemption-check-value-announce" class="a-button-text" aria-hidden="true">
<span id="gc-redemption-check-value-button-text" class="a-size-base">Check</span>
</span>
If the Jaunt thing is not work maybe you can try jQuery
$('.submitButton').click(function(){
$('form').submit();
});

onclick vs. $.post how to isolate a button function vs. submission? [duplicate]

I just found out that every time onclick event for my <button> placed inside <form> tag triggers, form submits it's data as if i clicked <input type='submit'>.
I don't want that. Buttons inside my form serve other task, form shouldn't submit data after i clicked one of them.
To be more clear, i want this code:
<form action="http://www.google.com" method="POST">
<button onclick="alert('hi!')">Button</button>
<br>
<input type="submit" value="submit"/>
</form>
to show alert "hi!" when i click on the Button and it shouldn't open Google after that. It should only show Google when i press "submit".
Specify type="button":
<button type="button" onclick="alert('hi!')">Button</button>
From the linked article:
This [submit] is the default if the attribute is not specified
Try this..
onclick="alert('hi!'); return false;"
With jQuery use a span rather than an input, put use the .button call and then set a click event.

If a disabled input button is clicked, display message

I have an input button, which when it is disabled, and someone tries to click it, needs to display an alert.
How is it possible to display a javascript message despite being disabled?
Tried this with no luck:
<input type="submit" onclick="alert('click')" value="Disabled Input Button" disabled/>
Use onmousedown instead of onclick, which is only fired when it is 'allowed' to. Some browsers, particularly Chrome, appear to disable all DOM events when a form element is disabled. While I think this is out of spec, you can use the following workaround:
Instead of using the disabled attribute, use CSS pointer-events to achieve a similar effect, illustrated here:
button.disabled {
pointer-events:none;
}
And then just use <button class="disabled"> instead of <button disabled>.
<span onclick="alert('This input is disabled')">
<input type="submit" value="Disabled Input Button" disabled/>
</span>
Wrapping it with another tag that has the on click function works.

how to add fancybox when an input submit button is clicked?

apparently it seems like this fancybox only works for anchor tags that has an ID or class ?,
but i want to use it in a submit button...is there a way to use it in that element ?
e.g this doesn't work because fancybox needs an href that will pull the contents
<input type="submit" id="submitme" name="submitme" value="SUBMIT ME" />
fancy box code
$("#submitme").fancybox();
Refer it by #,
$("#submitme").fancybox();
The issue is not whether fancybox can be bound to a submit button or not. The actual issue is that your submit button doesn't tell fancybox the target content to open and the type of content it is.
So having this :
<input type="submit" id="submitme" name="submitme" value="SUBMIT ME" />
... will work if you hard code the missing elements href and type in your costom script like :
$("#submitme").fancybox({
type : "iframe",
href : "http://jsfiddle.net"
});
See JSFIDDLE
Optionally, you can hard code any html content too like :
$("#submitme").fancybox({
content : "<p>Any html as content</p>"
});
See JSFIDDLE
You are missing the # in your node reference. But that's probably just because you typed out your code in the question. You could always style a hyperlink to look like a button, give it a URL and attach the fancybox to it:
<!--<input type="submit" id="submitme" name="submitme" value="SUBMIT ME" />-->
<a href="somewhere.htm" id="submitme" name="submitme" value="SUBMIT ME" >SUBMIT ME</a>
$("#submitme").click(function(event){
event.preventDefault();//stop the hyperlink from navigating away from the current page
}).fancybox();

Onclick shouldn't trigger form data submission

I just found out that every time onclick event for my <button> placed inside <form> tag triggers, form submits it's data as if i clicked <input type='submit'>.
I don't want that. Buttons inside my form serve other task, form shouldn't submit data after i clicked one of them.
To be more clear, i want this code:
<form action="http://www.google.com" method="POST">
<button onclick="alert('hi!')">Button</button>
<br>
<input type="submit" value="submit"/>
</form>
to show alert "hi!" when i click on the Button and it shouldn't open Google after that. It should only show Google when i press "submit".
Specify type="button":
<button type="button" onclick="alert('hi!')">Button</button>
From the linked article:
This [submit] is the default if the attribute is not specified
Try this..
onclick="alert('hi!'); return false;"
With jQuery use a span rather than an input, put use the .button call and then set a click event.

Categories