JSP and Javascripts on same page (Passing values to JSP fromJavascript)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Husain

    JSP and Javascripts on same page (Passing values to JSP fromJavascript)

    Hello.

    I have a button on a form which goes to a function validate in
    javascript as shown below:

    <input type="button" name="<%= i%>" value="Edit"
    onclick="valida te(this.name)">

    The javascript:

    <script language="javas cript">
    var Action="";
    function validate(Action ){
    var actstring = Action.toString ();
    ivalue = parseInt(actstr ing);
    return confirm('Ok for this action : '+ivalue+' ?'); //this is to
    test
    }
    </script>

    I am changing the ivalue to an integer which eventually will access an
    array built on the same page but using JSP. How can I pass the ivalue
    back to the JSP?

    Thank you.
  • Tom de Neef

    #2
    Re: JSP and Javascripts on same page (Passing values to JSP from Javascript)

    "Husain" <husranger@gmai l.com>
    I am changing the ivalue to an integer which eventually will access an
    array built on the same page but using JSP. How can I pass the ivalue
    back to the JSP?
    >
    Not very elegant: store it (as a string) in an invisible element of the
    document. JSP can read it there.
    Tom


    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: JSP and Javascripts on same page (Passing values to JSP fromJavascript)

      Husain wrote:
      I have a button on a form which goes to a function validate in
      javascript as shown below:
      >
      <input type="button" name="<%= i%>" value="Edit"
      onclick="valida te(this.name)">
      >
      The javascript:
      >
      <script language="javas cript">
      <script type="text/javascript">
      var Action="";
      function validate(Action ){
      By good convention, only identifiers referring constructors and constants
      should begin with a capital letter. You should know that one from Java.
      var actstring = Action.toString ();
      The type conversion is unnecessary as the value is a string value already.
      ivalue = parseInt(actstr ing);
      Should be:

      ivalue = parseInt(actstr ing, 10);

      But since you are setting the value and not the user, this conversion is
      unnecessary as well, at least in this particular code snippet.
      return confirm('Ok for this action : '+ivalue+' ?'); //this is to
      test
      }
      </script>
      >
      I am changing the ivalue to an integer which eventually will access an
      array built on the same page but using JSP. How can I pass the ivalue
      back to the JSP?
      Suppose you have

      <form action="...">
      ...
      <input type="hidden" name="formactio n" value="">
      ...
      </form>

      you could write something along

      <form action="..." onsubmit="valid ate(this)">
      <script type="text/javascript">
      function validate(f)
      {
      var action = arguments.calle e.action;
      f.action = action;
      return window.confirm( "Ok for this action: ' + action);
      }
      </script>

      <input type="submit" name="foo" value="Foo me!"
      onclick="valida te.action = this.name;">
      </form>

      But, as I said before in <news:4802A320. 9000903@Pointed Ears.de>, you should use

      <form action="handles _foo_and_bar_su bmits.jsp" ...>
      ...
      <input type="submit" name="foo" value="Foo me!">
      <input type="submit" name="bar" value="Bar me!">
      </form>

      instead, so that your application degrades gracefully. Since this is not
      exactly a new problem, I suggest you read these articles I posted not long ago:

      <news:47F03E18. 2040702@Pointed Ears.de>
      <news:47F50F52. 9060605@Pointed Ears.de>


      A request in advance: *Please trim your quotes to the necessary minimum.*


      PointedEars
      --
      Use any version of Microsoft Frontpage to create your site.
      (This won't prevent people from viewing your source, but no one
      will want to steal it.)
      -- from <http://www.vortex-webdesign.com/help/hidesource.htm>

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: JSP and Javascripts on same page (Passing values to JSP fromJavascript)

        Tom de Neef wrote:
        "Husain" <husranger@gmai l.com>
        >I am changing the ivalue to an integer which eventually will access an
        >array built on the same page but using JSP. How can I pass the ivalue
        >back to the JSP?
        >
        Not very elegant: store it (as a string) in an invisible element of the
        document. JSP can read it there.
        Not just any element, but <input type="hidden" ...in the form to be
        submitted. Else JSP will _not_ get at the value.


        PointedEars
        --
        var bugRiddenCrashP ronePieceOfJunk = (
        navigator.userA gent.indexOf('M SIE 5') != -1
        && navigator.userA gent.indexOf('M ac') != -1
        ) // Plone, register_functi on.js:16

        Comment

        Working...