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:form action="loginAction.do" >
    <script type="text/javascript">
        function test(){
            document.getElementById('dd').innerHTML =
                              "<html:text property='pid'/>";

            <table align="center">
                    <td align="center">
                    <input type="button" value="addprod" onclick="test()"/>
                    <td align="center">
                        <div id="dd"></div>

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.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.