
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2021 08:58 AM
I have a HTML like this:
<input class="chkbx" id="dt_1" ng-model="c.dt_1" type="checkbox" name="dt_1" onchange="chkVal()"/>
<script>
function chkVal(){
var checkBox1 = document.getElementById('dt_1');
if (checkBox1.checked == true){
//pass a value from this javascript to server script
}
else{
//pass a value from this javascript to server script
}
}
</script>
Solved! Go to Solution.
- Labels:
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2021 11:55 AM
Hi,
Instead of DOM manipulation use the ng-model variable and use the same in client controller and pass on the values to the server script.
HTML:
<input class="chkbx" id="dt_1" ng-model="c.data.dt_1" type="checkbox" name="dt_1" onchange="chkVal()"/>
Client Controller:
function chkVal(){
if (c.data.dt_1 == true){
c.data.checkbox =true;
}
else{
c.data.checkbox =false;
}
c.server.update();
}
Server Side:
if(input&&input.checkbox ){
gs.addinfomessge(input.checkbox);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2021 10:04 AM
Change your code to:
HTML:
<input class="chkbx" id="dt_1" ng-model="c.dt_1" type="checkbox" name="dt_1" onchange="c.chkVal()"/>
Client Controller:
c.chkVal = function(){
var checkBox1 = document.getElementById('dt_1');
if (checkBox1.checked == true){
c.data.yourVariableToPass = 'ServiceNow rockz';
c.server.update();
}
else{
c.data.yourVariableToPass = 'ServiceNow rockz';
c.server.update();
}
}
Server Script:
if(input)
{
if(input.yourVariableToPass)
{
gs.addInfoMessage(input.yourVariableToPass);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2021 11:55 AM
Hi,
Instead of DOM manipulation use the ng-model variable and use the same in client controller and pass on the values to the server script.
HTML:
<input class="chkbx" id="dt_1" ng-model="c.data.dt_1" type="checkbox" name="dt_1" onchange="chkVal()"/>
Client Controller:
function chkVal(){
if (c.data.dt_1 == true){
c.data.checkbox =true;
}
else{
c.data.checkbox =false;
}
c.server.update();
}
Server Side:
if(input&&input.checkbox ){
gs.addinfomessge(input.checkbox);
}