Set text using javascript and trigger change event

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))

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))

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”

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

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