# Set text using javascript and trigger change event

**URL:** <https://forum.katalon.com/t/set-text-using-javascript-and-trigger-change-event/27071>\
**Category:** Web Testing\
**Tags:** javascript, web-testing, katalon-studio\
**Created:** [June 5, 2019, 1:54pm UTC](https://forum.katalon.com/t/set-text-using-javascript-and-trigger-change-event/27071 "2019-06-05T13:54:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neeth\_Kunjappa](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Neeth\_Kunjappa](https://forum.katalon.com/u/Neeth_Kunjappa)\
**Post date:** [June 5, 2019, 1:54pm UTC](https://forum.katalon.com/t/set-text-using-javascript-and-trigger-change-event/27071/1 "2019-06-05T13:54:51Z")

</div>

I have a javascript that inputs text which works absolutely fine but since the event is not triggered ,the text is cleared off the text field as soon as the next step is executed.To avoid this I need to trigger the Change event but that doesn’t help too. Can someone help here.  
**Here is my script:**  
WebElement element = WebUiCommonHelper.findWebElement(findTestObject(‘LoginObjects/Phone’),30)  
WebUI.executeJavaScript(“arguments[0].value= ‘xxxx’;”, Arrays.asList(element))  
WebUI.executeJavaScript(“arguments[0].trigger(change);”, Arrays.asList(element))

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [June 5, 2019, 2:01pm UTC](https://forum.katalon.com/t/set-text-using-javascript-and-trigger-change-event/27071/2 "2019-06-05T14:01:59Z")

</div>

> [@Neeth\_Kunjappa](#):
>
> WebUI.executeJavaScript(“arguments[0].trigger(change);”, Arrays.asList(element))

That looks like jQuery.

1. Is jQuery available?
2. Is jQuery loaded and “ready”?
3. Did you check the browser console (F12 dev tools, open console).

Also, change the code to this (note the quotes around `'change'`)

WebUI.executeJavaScript(“arguments[0].trigger(`'change'`);”, Arrays.asList(element))

---

<div class="post-metadata">

**Author:** ![Neeth\_Kunjappa](https://avatars.discourse-cdn.com/v4/letter/n/a183cd/32.png) [@Neeth\_Kunjappa](https://forum.katalon.com/u/Neeth_Kunjappa)\
**Post date:** [June 5, 2019, 2:13pm UTC](https://forum.katalon.com/t/set-text-using-javascript-and-trigger-change-event/27071/3 "2019-06-05T14:13:26Z")

</div>

I hit jQuery on the console to check if its available and loaded but its doesnt look like jQuery is used as the output says “jQuery is not defined”

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [June 5, 2019, 2:24pm UTC](https://forum.katalon.com/t/set-text-using-javascript-and-trigger-change-event/27071/4 "2019-06-05T14:24:32Z")

</div>

> [@Neeth\_Kunjappa](#):
>
> the output says “jQuery is not defined”

In which case, you need to call the handler directly…

```javascript
// Call the element's onchange handler
WebUI.executeJavaScript("arguments[0].onchange();", Arrays.asList(element))

```

---

<div class="post-metadata">

**Author:** ![albert.vu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/albert.vu/32/20595_2.png) [@albert.vu](https://forum.katalon.com/u/albert.vu)\
**Post date:** [August 8, 2022, 7:48am UTC](https://forum.katalon.com/t/set-text-using-javascript-and-trigger-change-event/27071/5 "2022-08-08T07:48:41Z")

</div>

Archived on August 8, 2022, 7:48am UTC


