0

I need to bookmark a JavaScript function that, in certain conditions, should click a button on a webpage.

Right now, I have a bookmark saying "Hello..."

javascript:(function (){ alert('Hello ...'); })();

Instead of "hello..." I would like to have an HTML form with with 3 checkboxes and if all these 3 checkboxes are ticked, to automatically click a button on the webpage.

I'm not sure how I can include these functions into an alert box.

sam
  • 931
  • 2
  • 13
  • 26
Vishera
  • 133
  • 1
  • 7
  • https://stackoverflow.com/questions/6227507/javascript-alert-popup-form – Goombah Nov 25 '16 at 08:18
  • I didn't understand the issue. You need a `function` which will trigger another `function` when 3 checkboxes in an HTML form with are checked. Is it so? – sam Nov 25 '16 at 08:27
  • I misspelled it. Its just one function that pop-s up 3 checkboxes on the users screen. Once all these checkboxes are ticked, a button (ID=submit) on the webpage is pressed automatically by the function. – Vishera Nov 25 '16 at 08:29

1 Answers1

0

You can't do it in simple alert box. Consider using a modal window from 3rd party (ex. bootstrap modal: http://getbootstrap.com/javascript/#modals) or implement your own like described here: http://www.w3schools.com/howto/howto_css_modals.asp

Just for simple confirm dialog:

<button id="targetBtn" onclick="alert('Target Button click')">Target Button</button>
<button onclick="if (window.confirm('Do you really want to click Target Button?')){document.getElementById('targetBtn').click();}">Click me</button>
kubasz
  • 1
  • 1
  • It's not necessary to be an Alert. It can be a prompt as well. Or anything else that pop's up on the users screen – Vishera Nov 25 '16 at 08:22
  • I dont think a modal will work, as it needs heavy CSS styling. And I need to include this into a bookmark (link location field) in the browser – Vishera Nov 25 '16 at 08:35
  • 1
    A prompt dialog contains only one single-line textbox and OK/Cancel buttons. So it's not possible. – kubasz Nov 25 '16 at 08:46
  • @Vishera you can't popup checkboxes without modals. – sam Nov 25 '16 at 08:53
  • What about the 2nd part of the request, to make it without the checkboxes, just to display a message and after hitting OK, to automatically press a button on the webpage? – Vishera Nov 25 '16 at 09:00