简体   繁体   中英

Add text in the input field and submit using javascript

The end product I am trying to make is a browser extension that will fill the coupon field and press apply/submit. I am currently just testing in the browser console to check what works.

Every input field that takes in a coupon always has a couponinputbound = true attribute. So I just use:

 var x = document.querySelector("input[couponinputbound]") x.value = "COUPONCODE"

When I enter the above code, I can see the text appear in the input field, however on inspection, I found the value attribute of the input field to be empty.

I am trying to use a simple.click() on the button, but since the value of the input field is empty, the button remains disabled.

输入字段显示新文本,但值属性在输入中保持为空

What if we remove the disable from the apply button. Will it work if you click on the button?

it would be something like this below

 var x = document.querySelector("input[couponinputbound]") var applyButton = document.querySelector("button[aria-label='Apply']") applyButton.disabled = false x.value = "COUPONCODE"

Set the value attribute instead of the value property like this:

x.setAttribute('value','COUPONCODE');

It will change the value attribute as well as the displayed text in the input element.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM