Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

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

Hi,

any browser console error?

Regards
Ankur

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

Jahnavi6
Kilo Expert

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

Thanks!

@Jahnavi 

Did you accidentally marked your own response as correct.

Would you mind marking my response as correct and helpful if I was able to help/guide you.

Regards
Ankur

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