- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 04:05 AM
I have a ui page and when I try to get the values of input it says "Cannot read properties of null (reading 'value')".
My HTML code is:
<html>
<body>
<form>
<g:ui_reference name="Table" id="table" table="sys_db_object" completer="AJAXTableCompleter" ng-model="table"/>
<g:ui_reference name="Template" id="template" table="sys_template" completer="AJAXTableCompleter" ng-model="template"/>
<input type="button" onclick="onSubmit()" value="Submit"></input>
</form>
</body>
</html>
My client script is
function onSubmit(){
var table = document.getElementById("table").value;
var template = document.getElementById("template").value;
alert(table+template);
}
Any help would be appreciated
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 05:09 AM
Hi
you need to ensure the name and the id attribute have same value for <g:ui_reference>
This will work now
<html>
<body>
<form>
<g:ui_reference name="table" id="table" table="sys_db_object" completer="AJAXTableCompleter" ng-model="table"/>
<g:ui_reference name="template" id="template" table="sys_template" completer="AJAXTableCompleter" ng-model="template"/>
<input type="button" onclick="onSubmit()" value="Submit"></input>
</form>
</body>
</html>
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
06-23-2022 04:48 AM
Hi, Used below code
<html>
<body>
<form>
<g:ui_reference name="table_val" id="table_val" table="sys_db_object" completer="AJAXTableCompleter" ng-model="table"/>
<g:ui_reference name="template_val" id="template_val" table="sys_template" completer="AJAXTableCompleter" ng-model="template"/>
<input type="button" onclick="onSubmit()" value="Submit"></input>
</form>
</body>
</html>
In client script
function onSubmit() {
var num = gel('table_val').value.toString();
var value = gel('template_val').value.toString();
alert("Table value--"+table_val+"Template val--"+template_val);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 05:09 AM
Hi
you need to ensure the name and the id attribute have same value for <g:ui_reference>
This will work now
<html>
<body>
<form>
<g:ui_reference name="table" id="table" table="sys_db_object" completer="AJAXTableCompleter" ng-model="table"/>
<g:ui_reference name="template" id="template" table="sys_template" completer="AJAXTableCompleter" ng-model="template"/>
<input type="button" onclick="onSubmit()" value="Submit"></input>
</form>
</body>
</html>
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader