简体   繁体   中英

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 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.

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).

它应该在<body>标记中工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM