开发者

writing html bean within JavaScript

hey Guys, I am trying to write dynamic html bean using java script but I keep geting the "function is not found" JS error when I press the button .. here is a sample code

<html>
<html:form action="loginAction.do" >
<head>
    <script type="text/javascript">
        function test(){
            document.getElementById('dd').innerHTML =
           开发者_运维技巧                   "<html:text property='pid'/>";
        }
    </script>

</head>
<body>
            <table align="center">
                <tr>
                    <td align="center">
                    <input type="button" value="addprod" onclick="test()"/>
                    </td>
                </tr>
                <tr>
                    <td align="center">
                        <div id="dd"></div>
                    </td>
                </tr>
            </table>
    </html:form>
</body>
</html>

I don't know about the

<html:form action="loginAction.do" >

where it should be located I tried to locate it within the <body> but I got a big exception due to writing <html:text property='pid'/> in JavaScript outside the <html:form> ... need your help, Regards,


I think struts is trying to parse the <html:text /> as a tag in your script, rather that just a javascript string. Try moving the <html:form action="loginAction.do" > into the body AND the <script> within the <html:form> similar to this fiddle http://www.jsfiddle.net/pL4Aq/1/

However, it works in the fiddle because it is just straight HTML... I don't think what you are trying to do will work. <html:text > is a custom tag that gets processed on the server, does a bunch of stuff, and then generates HTML for you. You will never actually see <html:text> if you view the source from your browser, even though it is in your jsp.

You might want to try changing the <html:text > to a straight <input type="text"> tag (in which case, you could just move the <html:form> into the body and leave the script where it is).


I am completely agreed with what Mike is saying.
Writing <html:text> inside javascript is useless since javascript is executing on client side while struts is required to translate this tag to html tag.
Better to write <input type="text"> inside javascript and keeps its name as "prop" if you want struts to fill the value of that text inside the form bean property "prop". Keep the <html:form in body tag. This will work for you.


It should work in a <body> tag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜