Getting Error as "[object HTMLDivElement]" in alert.

Anusha Savanth
Tera Expert

while I am trying the below Script , I am getting a Output as below

[object HTMLDivElement].

 

Script:

function onSubmit() {
    //Type appropriate comment here, and begin script below

    var oci_nt_val;
    var answer;

    var acct_name = g_form.getValue('accountName');

    var a = new GlideAjax('cidr_POST');
    a.addParam('sysparm_acct_name', acct_name);
    a.getXML(getResponse);


    function getResponse(response) {
        answer = response.responseXML.documentElement.getAttribute("answer");

        alert('Network Value : ' + answer.substring(answer.indexOf('-') + 1))

        oci_nt_val = answer.substring(0, answer.indexOf('-'));

        g_form.setValue('httpstatus_value', oci_nt_val);

         alert("HttpStatus : " + httpstatus_value);  // Here getting alert as Http Status : [object HTMLDivElement]
        
    }
    
}

 

Please suggest me the code

2 REPLIES 2

Michael Jones -
Giga Sage

In your script you do not define httpstatus_value as a javascript variable, but in your alert you are calling it has such. Are you trying to display the value of the field you just set? You would need to call a method, not the field name. 

alert("HttpStatus : " + g_form.getValue("httpstatus_value"));  // Here getting alert as Http Status : [object HTMLDivElement]

I hope this helps!

If this was helpful, or correct, please be kind and mark the answer appropriately.

Michael Jones - Proud member of the GlideFast Consulting Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

It is working. Thank you.

 

I have added like this,

 alert("HttpStatus : " + g_form.getValue('httpstatus_value') + " " + typeof(httpstatus_value)); 

and It is giving output as Object type. How to convert it to String and add to variable.

output

HttpStatus : 200 object