Javascript Button Pressing

After digging into the forum and the many (112) javascript posts, I am still not getting this. A friend wants to hit a button on a javascript form. I understand that "Execute JavaScript in Front Browser" is what I need, but cannot figure out the code. Here is the button code in question:

<div class="sheet-col">
	<label for="attr_cool" class="sheet-orange" data-i18n="cool">Cool</label>
	<input name="attr_cool" type="number" value="0">
	<button type="roll" 
      value="&amp;{template:spr_desc} {{roll_tabledescname=@{name}}} {{roll_tabledescvalue=^{rolls-cool}}} {{roll_imageurl=@{fileimg}}} {{roll_imagedesc=^{file-image}}} {{roll_value2name=^{total}}} {{roll_value2value=[[2d6+@{cool}[cool]+?{Forward|0}[forward]]]}} {{roll_value1name=^{forward}}} {{roll_value1value=[[(?{Forward|0})]]}}" 
      class="btn ui-draggable">
    </button>
    <br>
	<span class="sheet-translate" data-i18n="act-under-pressure">Act Under Pressure</span><br>
	<span class="sheet-translate" data-i18n="apply-first-aid">Apply First Aid</span>
</div>

That "roll" button is what I am after. Any help is greatly appreciated.

Vic

I revised your post to put the HTML code in a Code Block.

We cannot properly test your HTML code snippet because it is incomplete and non-functional.

But here is my best un-tested guess, which can serve as a starting point for you:

var scriptResults = 'TBD';
var btn = document.querySelector('button.btn.ui-draggable[type="roll"]');
if (btn) {
  btn.click();
  scriptResults = 'OK';
} else { scriptResults = '[ERROR]  button.btn.ui-draggable was NOT found.'; }

scriptResults;

Hey Vic,

Welcome to the forum!   :smile:

Do you really need the roll button?

Or can you enter a value directly into the field?

document.querySelector("div > input[name=attr_cool]").value = 200

-Chris

Some progress. That enters the value, but does not activate the roll button. @JMichaelTX solution did not seem to do anything. That said, I think he is on the right track, but I am not sure what I am reading. Would posting the entire page's code help?

Thank you,

Vic

Yes, definitely. Or a URL to it. Or both :slight_smile:

Definitely!

full_page.zip (11.9 KB)

Grabbed the complete code in the attached zip.

Thank you,

Vic

1 Like

Thanks for the HTML code. In the future please store the HTML code in a PLAIN text file.

That button does NOT work for me in the Browser when I click on it:

Does it work for you, or is this not the target button?

If it works for you, we will need for your to post the URL to the page, because the live web page may be different from the static HTML code.

The only solution would be to create a login for you and then you could execute in a real environment. If you are game, I will get it done.

Vic

Before we do that let's try this:

  1. Open your web page and log in
  2. Right click on the target button, and select "Inspect"
    • image
  3. Copy outerHTML of <div class="sheet-column6>

Hopefully that will provide us with the live HTML code that we need to use.

Back to the web page: Click on the button, and make a screen capture of the region that results.
Paste that screen capture into this Forum.

1 Like
<div class="sheet-column6"><div class="sheet-col"> <label for="attr_cool" class="sheet-orange" data-i18n="cool">Cool</label><input name="attr_cool" type="number" value="0"> <button type="roll" value="&amp;{template:spr_desc} {{roll_tabledescname=@{name}}} {{roll_tabledescvalue=^{rolls-cool}}} {{roll_imageurl=@{fileimg}}} {{roll_imagedesc=^{file-image}}} {{roll_value2name=^{total}}} {{roll_value2value=[[2d6+@{cool}[cool]+?{Forward|0}[forward]]]}} {{roll_value1name=^{forward}}} {{roll_value1value=[[(?{Forward|0})]]}}" class="btn ui-draggable"></button><br> <span class="sheet-translate" data-i18n="act-under-pressure">Act Under Pressure</span><br> <span class="sheet-translate" data-i18n="apply-first-aid">Apply First Aid</span></div><div class="sheet-col"> <label for="attr_edge" class="sheet-orange" data-i18n="edge">Edge</label><input name="attr_edge" type="number" value="0"> <button type="roll" value="&amp;{template:spr_desc} {{roll_tabledescname=@{name}}} {{roll_tabledescvalue=^{rolls-edge}}} {{roll_imageurl=@{fileimg}}} {{roll_imagedesc=^{file-image}}} {{roll_value2name=^{total}}} {{roll_value2value=[[2d6+@{edge}[edge]+?{Forward|0}[forward]]]}} {{roll_value1name=^{forward}}} {{roll_value1value=[[(?{Forward|0})]]}}" class="btn ui-draggable"></button><br> <span class="sheet-translate" data-i18n="assess">Assess</span><br> <span class="sheet-translate" data-i18n="play-hardball">Play Hardball</span></div><div class="sheet-col"> <label for="attr_meat" class="sheet-orange" data-i18n="meat">Meat</label><input name="attr_meat" type="number" value="0"> <button type="roll" value="&amp;{template:spr_desc} {{roll_tabledescname=@{name}}} {{roll_tabledescvalue=Rolls Meat}} {{roll_imageurl=@{fileimg}}} {{roll_imagedesc=^{file-image}}} {{roll_value2name=^{total}}} {{roll_value2value=[[2d6+@{meat}[meat]+?{Forward|0}[forward]]]}} {{roll_value1name=^{forward}}} {{roll_value1value=[[(?{Forward|0})]]}}" class="btn ui-draggable"></button><br> <span class="sheet-translate" data-i18n="mix-it-up">Mix It Up</span><br> <span class="sheet-translate" data-i18n="acquire-agri-property">Acquire Agri Property</span></div><div class="sheet-col"> <label for="attr_mind" class="sheet-orange" data-i18n="mind">Mind</label><input name="attr_mind" type="number" value="0"> <button type="roll" value="&amp;{template:spr_desc} {{roll_tabledescname=@{name}}} {{roll_tabledescvalue=^{rolls-mind}}} {{roll_imageurl=@{fileimg}}} {{roll_imagedesc=^{file-image}}} {{roll_value2name=^{total}}} {{roll_value2value=[[2d6+@{mind}[mind]+?{Forward|0}[forward]]]}} {{roll_value1name=^{forward}}} {{roll_value1value=[[(?{Forward|0})]]}}" class="btn ui-draggable"></button><br> <span class="sheet-translate" data-i18n="research">Research</span></div><div class="sheet-col"> <label for="attr_style" class="sheet-orange" data-i18n="style">Style</label><input name="attr_style" type="number" value="0"> <button type="roll" value="&amp;{template:spr_desc} {{roll_tabledescname=@{name}}} {{roll_tabledescvalue=^{rolls-style}}} {{roll_imageurl=@{fileimg}}} {{roll_imagedesc=^{file-image}}} {{roll_value2name=^{total}}} {{roll_value2value=[[2d6+@{style}[style]+?{Forward|0}[forward]]]}} {{roll_value1name=^{forward}}} {{roll_value1value=[[(?{Forward|0})]]}}" class="btn ui-draggable"></button><br> <span class="sheet-translate" data-i18n="fast-talk">Fast Talk</span><br> <span class="sheet-translate" data-i18n="hit-the-street">Hit The Street</span></div><div class="sheet-col"> <label for="attr_synth" class="sheet-orange" data-i18n="synth">Synth</label><input name="attr_synth" type="number" value="0"> <button type="roll" value="&amp;{template:spr_desc} {{roll_tabledescname=@{name}}} {{roll_tabledescvalue=^{rolls-synth}}} {{roll_imageurl=@{fileimg}}} {{roll_imagedesc=^{file-image}}} {{roll_value2name=^{total}}} {{roll_value2value=[[2d6+@{synth}[synth]+?{Forward|0}[forward]]]}} {{roll_value1name=^{forward}}} {{roll_value1value=[[(?{Forward|0})]]}}" class="btn ui-draggable"></button><br> <span class="sheet-translate" data-i18n="use-cyberware">Use Cyberware</span></div></div>

Not sure about the screen shot info. Is this what you needed?

@vicpylon, OK thanks.
The button will still NOT work for me when clicked, but I think this revised script should work. Please try it:

var scriptResults = 'TBD';
var btn = document.querySelector('div.sheet-column6 button.btn.ui-draggable[type="roll"]');
if (btn) {
  btn.click();
  scriptResults = 'OK';
} else { scriptResults = '[ERROR]  button.btn.ui-draggable was NOT found.'; }

scriptResults;