1

I have an application that uses struts 2. My problem is whenever I'm using IE, I get the attribute value fine from my HTML page to my action class, but when I use firefox, I'm getting a null value.

I'm using javascript to dynamically create the textarea where I map the value of my action class attribute "explanation".

function showExplain(){

    if(document.getElementById("equivalentExp").checked){
        document.getElementById('explaintxt').style.display = "inline";

        var taspan = document.getElementById("taSpan");

        var ta = document.createElement('textarea');
        ta.setAttribute("name", "explanation");
        ta.setAttribute("id", "explanation");
        ta.setAttribute("cols", "45");
        ta.setAttribute("rows", "5");
        ta.setAttribute("class", "textAreaField");
        ta.innerHTML = '<%if(explanation != null){%><%= explanation %><%}%>';
        taspan.appendChild(ta);
    }else{
        document.getElementById('explaintxt').style.display = "none";
        if(document.getElementById("explanation") != null){
            var taspan = document.getElementById("taSpan");
            taspan.removeChild(document.getElementById("explanation"));
        }
    }
}

I have my getter/setter for the "explanation" attribute in my action class, so I know that's not the problem. I also tried to alert("document.getElementById("explanation").value); and it's displaying the right value that I have in my textarea, both in IE and firefox, but when it get to the controller, it's null when I use firefox.

I also tried to just use a regular textarea declared in the html, it works fine in both browsers.

What's confusing is why doesn't the value reach my action class, when, before submitting the form, I have the right value when I try to display it.

I'm stuck, does anyone have an answer to this?

Thanks,

mandirigma
  • 11
  • 2
  • I'm pretty sure you don't want to use innerHTML for this. http://stackoverflow.com/questions/1642447/how-to-change-the-content-of-a-textarea-with-javascript – Dave Newton Sep 13 '11 at 22:36
  • I tried it, still the same. Got the value using IE, null when using FF. – mandirigma Sep 13 '11 at 23:08
  • Update with the current code; I'm not really sure how that can't work. Either way, nothing to do with Struts. Also, why are you doing all this? Couldn't you just set the style to display: none if there's nothing there and keep all of this in HTML where it belongs? – Dave Newton Sep 13 '11 at 23:18
  • yes, I guess I can do that. I just wanted to avoid getting a blank string in my action class, but I guess I'll just add some validation to my action class. But I still want to know why this is happening using the dynamic method though. BTW, I updated ta.innerHTML = '<%if(explanation != null){%><%= explanation %><%}%>'; with ta.value = '<%if(explanation != null){%><%= explanation %><%}%>'; but still doesn't work. – mandirigma Sep 13 '11 at 23:45
  • Then wrap the entire textarea with an if statement. Is it rendering the way you expect when you view source? – Dave Newton Sep 14 '11 at 00:04

0 Answers0