Calling array through an alert

kunal16
Tera Expert

I have wrote a script include for an array outcome. I am calling the same script include through a client script. What I need is to get an alert/pop-up alert to display the result of the same array. How can that be achieved?

1 ACCEPTED SOLUTION

Hi Kunal,



Instead of alerting it in the loop just add it and display it after the loop's finished:



  1.   function _processResponse(response) {
  2.           var userAttributes = response.responseXML.getElementsByTagName("userAttributes"),
  3.                   sStringToAdd = "",
  4.                   sAnswer = "";
  5.           for (var i=0; i<userAttributes.length; i++){
  6.                       sStringToAdd = i<userAttributes.length - 1 ? userAttributes[i].getAttribute("value") + "," : userAttributes[i].getAttribute("value") + "";
  7.                       sAnswer += sStringToAdd;
  8.           }
  9.           alert(sAnswer);
  10.   }


Cheers



Greg


View solution in original post

11 REPLIES 11

  1. var userAttributes = response.responseXML.getElementsByTagName("userAttributes");  
  2.             for (var i=0; i<userAttributes.length; i++){  
  3.                       alert(userAttributes[i].getAttribute("value"));


what to add to the above code to get the comma separated result


Just use a normal array at server side instead of Json and return it.


I am exactly using the code given by Berny. It is able to fetch the answer.


  1.   function _processResponse(response) {  
  2.             var userAttributes = response.responseXML.getElementsByTagName("userAttributes");  
  3.             for (var i=0; i<userAttributes.length; i++){  
  4.                       alert(userAttributes[i].getAttribute("value"));  
  5.             }  
  6.   }

It is showing :


Alert(INC0000001)


Alert(INC0000001)



I need:


alert(INC0000001,INC0000002)



so I need to know what needs to be added to the above code(client side) to get the required answer


I am exactly using the code given by Berny. It is able to fetch the answer.


  1.   function _processResponse(response) {
  2.             var userAttributes = response.responseXML.getElementsByTagName("userAttributes");
  3.             for (var i=0; i<userAttributes.length; i++){
  4.                       alert(userAttributes[i].getAttribute("value"));
  5.             }
  6.   }

It is showing :


Alert(INC0000001)


Alert(INC0000002)



I need:


alert(INC0000001,INC0000002)



so I need to know what needs to be added to the above code(client side) to get the required answer


Hi Kunal,



Instead of alerting it in the loop just add it and display it after the loop's finished:



  1.   function _processResponse(response) {
  2.           var userAttributes = response.responseXML.getElementsByTagName("userAttributes"),
  3.                   sStringToAdd = "",
  4.                   sAnswer = "";
  5.           for (var i=0; i<userAttributes.length; i++){
  6.                       sStringToAdd = i<userAttributes.length - 1 ? userAttributes[i].getAttribute("value") + "," : userAttributes[i].getAttribute("value") + "";
  7.                       sAnswer += sStringToAdd;
  8.           }
  9.           alert(sAnswer);
  10.   }


Cheers



Greg