- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 06:08 AM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2021 01:50 AM
Thanks for your reply. I've got it fixed by changing the onchange function name from "show" to "somethingelse".
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 06:25 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 06:34 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 06:44 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 06:57 AM
no luck, still the same. onchange is not firing.