Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to access selected value of the dropdown in "processing script" in UI page

Jahnavi6
Kilo Expert

Hi, I need the selected dropdown value in the processing script, so that, based on the selected value, i need to redirect to some other page. Here is my HTML code:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
	<g:ui_form>
		<select id="sel" name="sel" onchange="show(this)" style="width:400px">
			<option value="">-- Select --</option>
		</select>
		<g:ui_spacer />
		<g:dialog_button_ok ok_id="ok_button" />
		<input type="hidden" name="univValue" id="univValue" value="" />
	</g:ui_form>
</j:jelly>

Client Script: 

$j(function() {
	var ga = new GlideAjax('FetchUniversities');
	ga.addParam('sysparm_name', 'getUniversitiesList');
	ga.getXML(callbackMethod);
	

});
function show(ele) {
	alert(ele);
	document.getElementById('univValue').value =  ele.options[ele.selectedIndex].value;
}

function callbackMethod(response) {
	var answer = response.responseXML.documentElement.getAttribute('answer');
	answer = JSON.parse(answer);
	try {
		var ele = document.getElementById('sel');
		var data1 = answer.data.identityProvider.providers;
		for (var i = 0; i < data1.length; i++) {
			ele.innerHTML = ele.innerHTML +
				'<option value="' + data1[i]['idp'] + '">' + data1[i]['name'] + '</option>';
		}
	} catch (e) {
		return;
	}
}

 

Processing Script: 

 

gs.info("checbox value is : " + univValue);
if (univValue != '') {
       my_target = 'newpage.do';
} else {
       my_target = 'navpage.do';
}
response.sendRedirect(my_target);

 

It looks like the "onchange" function is not firing, and in the console i'm getting "actionOK" is not defined error when i click on "OK" button.

1 ACCEPTED SOLUTION

Jahnavi6
Kilo Expert

Thanks for your reply. I've got it fixed by changing the onchange function name from "show" to "somethingelse". 

Thanks!

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Did you see the options are getting added?

Update as this

<g:dialog_buttons_ok_cancel ok_text="${gs.getMessage('OK')}" ok="return ok_button();" cancel="return cancel();"/>

Client Script:

$j(function() {
	var ga = new GlideAjax('FetchUniversities');
	ga.addParam('sysparm_name', 'getUniversitiesList');
	ga.getXML(callbackMethod);
	

});
function show(ele) {
	alert(ele);
	document.getElementById('univValue').value =  ele.options[ele.selectedIndex].value;
}

function onCancel() {
	GlideDialogWindow.get().destroy();
	return false;
}

function ok_button(){
return true;
}

function callbackMethod(response) {
	var answer = response.responseXML.documentElement.getAttribute('answer');
	answer = JSON.parse(answer);
	try {
		var ele = document.getElementById('sel');
		var data1 = answer.data.identityProvider.providers;
		for (var i = 0; i < data1.length; i++) {
			ele.innerHTML = ele.innerHTML +
				'<option value="' + data1[i]['idp'] + '">' + data1[i]['name'] + '</option>';
		}
	} catch (e) {
		return;
	}
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Yes, the options are added to the dropdown. ANd, still the same issue "ok_button" is not a function issue. And the alert in the "show" function is not showing up when i change the value in the dropdown.

Hi,

then update as this

<select id="sel" name="sel" onchange="show()" style="width:400px">
			<option value="">-- Select --</option>
		</select>

Client Script:

function show() {

	document.getElementById('univValue').value =  gel('sel').value;
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

no luck, still the same. onchange is not firing.