Discussions

Web tier: servlets, JSP, Web frameworks: javascript with struts

  1. javascript with struts (5 messages)

    Hi,
        I am doing a lot of javascript on the client side while using struts on the server side.
          My problem is that I cannot use "document.form.component....." in my javascript because the form name comes from the <form-bean name="FormName"> tag in the struts config.
         Is there a way to get the form name in my jsp?

    Thanks,

    Sandeep Tiwary

    Threaded Messages (5)

  2. Re: javascript with struts[ Go to top ]

    You can pass "this.form" as a parameter into the JavaScript function. This way you don't need to explicitly specify the form name.
  3. Re: javascript with struts[ Go to top ]

    Thanks Alan, but I need to call my javascript in <body onLoad="function()"> so I dont have a reference to my form at this time.
  4. Re: javascript with struts[ Go to top ]

    In this case, you can use document.forms[0] to reference it if this is the first form in your page (index 1 for second, 2 for thrid etc.).
  5. Hi ,

    I have a print button on my Jsp page which invokes the print option.

    My problem is... I have written a fun printScreen()
    in which i am invoking window.print()..the next line is submitting the form calling "somePage.do".

    When I click the print button....it invokes the print dialog box and then submits the form which returns the next Jsp page.

    What I want is when Print is invoked I dont want to submit the form unless user has decided to print (Whether Ok or cancel). I only want to submit the form when User clicks Ok/Cancel button of the print dialog box.

    Is it possible to do that? Does window.print() returns any value ? By using that return value i can write if-else to submit the for....

    Please let me know if you guys have any clue.

    Thanks in advance.

    Abhishek
  6. javascript with struts[ Go to top ]

    There is several ways :
    1. If you know the sequence of the form object in the page, for example your form is always the first form, use :
    document.forms[0]..... and for second form : document.forms[1]..... and so on.
    2.In your JSP, you can write a hidden field that you know the name of it in javascript, and the value of that hidden is your form name, then use :
    Var hiddenValue = document.getElementById("hiddenId").value;
    document.forms[hiddenValue].......
    where hiddenId is the Id attribute of the hidden field.