1

I am trying to pass an array of strings to a javascript function from jsp.

Following is the part of code that calls the function:

<a href="#" onclick='loadData("<%=entry.getDisplayName()%>","<%=entry.getModuleName() %>","<%=entry.getFileDesc()%>","<%=entry.getFileID()%>")'>Edit</a>

Entry is an object and the type for ModuleName is as follows:

private String[] moduleName;

I have put proper getters and setters for the same.

This is the function implementation part:

    function loadData(val1, val2, val3, val4) {
    document.getElementById("editDisplayName").value = val1;
    document.getElementById("selectedFile").innerHTML = val1
            + '<span><a onclick="displayUpload()" style="padding: 10px; cursor: pointer; cursor: hand;">X</a>';
    document.getElementById("editDescription").value = val3;
    document.getElementById("fileID").value = val4;
    var modules = val2;
    for(var index=0;index < modules.length;index++)
        {
        alert(modules[index]);
        }

    jQuery('#edit-form').dialog('open');
    return false
}

When run, it shows gibberish values.

Can someone please tell me what am I doing wrong??

5
  • what are those gibberish values? Commented Jan 31, 2017 at 12:46
  • @marmeladze The value is [Ljava.lang.string@527c72ab . Commented Jan 31, 2017 at 12:50
  • please have a look into this enter link description here Commented Jan 31, 2017 at 13:07
  • @GilbertoSantos I have put the code into a jsp file. Also, i cannot do : var modules = "<%=entry.getModuleName() %>" since the value entry is iterated for an arraylist of objects. Commented Jan 31, 2017 at 13:19
  • @JozefChocholacek I would refer my js code to handle the conversion. Commented Feb 1, 2017 at 8:04

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.