0

This is my jsp code where I am trying to push some data in javaScript array.

 <%
    int proListSize =  proList.size(); 

ProfileDAO proDAO = null;

            for(int i = 0, j=1; i < proListSize; i++){

                proDAO = (ProfileDAO)proList.get(i);%>

        entireArray.push(<%= proDAO.getNetworkmapId()%> + ":"+<%=proDAO.getAssetId()%> + ":" + <%= proDAO.getCode()%>);

        <%} %>

And this is the function where I am trying to use it by using pop function.

function GenDemographicTag() {

 var ptag = "<!-- Begin "+networkNameToUpperCase+" -->\n" ;
            var t = "";
             if (WhiteTagLabelDomain) {
                ptag += "<iframe src=\"http://"+WhiteTagLabelDomainTrim+"/jsc/"+folderName+"/dm.html?";
             } else {
                ptag += "<iframe src=\"http://"+cdnName+"/jsc/"+folderName+"/dm.html?";
             }
            ptag += "n="+networkId+";";

            for(var i = 0;i< entireArray.length;i++){
                var combinedString = entireArray.splice(1,1);
                var rightSide = combinedString.split(':')[0];
                var middle = combinedString.split(':')[1];
                var leftSide = combinedString.split(':')[2];
            t = "";
            if ( $("proElementEnable_"+rightSide) && $("proElementEnable_"+leftSide).checked) {
                if ( middle == "1") {
                   if ( $("zip").value.length <= 0) {
                     t = "0";
                    } else {
                  t =  $("zip").value;
                    }
                } else if ( $("targetList_"+rightSide) && $("targetList_"+rightSide).length > 0 &&  $("targetList_"+rightSide).options[0].value != "-1") {
                    t =  makeProelementList($("targetList_"+rightSide));
                 }
                ptag += leftSide+"=" + t+ ";";
            }

             proDAO = null;
            }

            ptag += "\" frameborder=0 marginheight=0 marginwidth=0 scrolling=\"no\" allowTransparency=\"true\" width=1 height=1>\n</iframe>\n<!-- end "+networkNameToUpperCase+"   -->\n";

            document.forms[0].tag.value = ptag;

        }

Basically I am trying to get the data from proList and store it in javaScript array(entireArray)...so that I can use in the javascript function..but after doing the above I get a javaScript error as follow:

entireArray.push(3 + ":"+3 + ":" + d3);

entireArray.push(185 + ":"+5 + ":" + d4);

entireArray.push(2 + ":"+2 + ":" + d2);

entireArray.push(186 + ":"+5 + ":" + d9);

entireArray.push(183 + ":"+5 + ":" + d6);

entireArray.push(184 + ":"+5 + ":" + d7);

entireArray.push(187 + ":"+5 + ":" + da);

entireArray.push(445 + ":"+5 + ":" + db);

Reference Error:d3 is not defined.  

what is the exact problem..?

2 Answers 2

2

The return type of splice is an ARRAY , so you can try following code

var combinedString = entireArray.splice(1,1);
var rightSide = combinedString[0].split(':')[0];
var middle = combinedString[0].split(':')[1];
var leftSide = combinedString[0].split(':')[2];
Sign up to request clarification or add additional context in comments.

Comments

0

d3 should be in quotes. "d3"

You need to put the out of JSP in quotes.

entireArray.push(<%= proDAO.getNetworkmapId()%> + ":"+<%=proDAO.getAssetId()%> + ":" + '<%= proDAO.getCode()%>');

1 Comment

hey that helped..but now I am getting another JavaScript error stating that Type Error: combinedString.Split is not a function...but I checked that split is surely a function in javascript...any alternative for this will also do...can you suggest anything

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.