-2

I'm building a bot that automatically fills and submits a form. I've searched through web and I found

document.querySelector('input[name="input_price"]').value = '2';

and

var el = document.getElementsByName("input_price")[0];
el.value = "$2.00"

both work - they fill input. But when input is filled, a checkbox is supposed to come up, and it doesn't. Without checkbox I can't continue. If I manually add literally anything to input, checkbox comes up. Is there any way to fix this?

Vasan
  • 4,810
  • 4
  • 20
  • 39
  • 3
    Please include the code that controls the checkbox. My guess is that it's using a listener that isn't being fired (for example, "onkeypress") – Alex May 01 '18 at 16:56

1 Answers1

-1

The displaying of the checkbox is probably triggered by a change event on the input field. This event is triggered by the browser when a user enters a value manually, but when you change the value using JavaScript, it is not triggered.

You can trigger the event programmatically like this:

var el = document.getElementsByName("input_price")[0];
el.value = "$2.00";
el.dispatchEvent(new Event('change'));

See related question on Stack Overflow.

Patrick Hund
  • 19,163
  • 11
  • 66
  • 95
  • doesn't work, value is changed but checkbox still doesn't come up, it just returns "true" – overwatch227 May 01 '18 at 17:02
  • 1
    Why would you downvote an answer like that? It might not be suggesting the correct event (it might also be keydown, keypress, keyup, blur and so on), but it showed you the way to solve it. – jirig May 01 '18 at 17:05
  • If change doesn't do the trick, then the JavaScript on the site you're trying to manipulate is probably listening for some other event, perhaps `keypress` or `keyup` – Patrick Hund May 01 '18 at 17:06
  • i didn't downvote it, post got -2 as well, someone's messing around – overwatch227 May 01 '18 at 17:07
  • Try this: `el.dispatchEvent(new KeyboardEvent('keypress', {'key': 'a'}))` – Patrick Hund May 01 '18 at 17:08
  • still returns "true" and nothing else, thanks anyway – overwatch227 May 01 '18 at 17:10
  • 2
    @overwatch227 Without the code which controls checkbox display, any answers given are just shots in the dark. – Vasan May 01 '18 at 17:17
  • @Vasan that's true. @overwatch227, one last try: use `keyup` instead of `keypress`, if that doesn't help, I don't know either – Patrick Hund May 01 '18 at 17:18
  • well this is website https://steamcommunity.com/market/listings/578080/Leather%20Hoodie%20%28Black%29# it's in BUY but you need have steam account to actually see what i'm talking about, which you probably don't xD thanks anyways – overwatch227 May 01 '18 at 17:27