text box changes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lavanyak6
    New Member
    • Jan 2008
    • 2

    text box changes

    have written a code for textbox in jsp

    [HTML]<td><input type="text" class="textBox" name="potCommis sion" id="potCommissi on" size="10" value='<%=commi ssion%>'
    <% if(!commissionF lag.equals("NG" )){ %> disabled="true" <%}%> ></td>[/HTML]

    whenever the page loads the textbox contains the same value the user has typed in. I want it to be defaulted it to '0.00' whenever the page is refreshed. any inputs?
    Last edited by acoder; Jan 12 '08, 11:43 AM. Reason: Added code tags
  • sumittyagi
    Recognized Expert New Member
    • Mar 2007
    • 202

    #2
    Originally posted by lavanyak6
    have written a code for textbox in jsp

    [HTML]<td><input type="text" class="textBox" name="potCommis sion" id="potCommissi on" size="10" value='<%=commi ssion%>'
    <% if(!commissionF lag.equals("NG" )){ %> disabled="true" <%}%> ></td>[/HTML]

    whenever the page loads the textbox contains the same value the user has typed in. I want it to be defaulted it to '0.00' whenever the page is refreshed. any inputs?
    Try this:
    [HTML]<body onload="documen t.getElementByI d('potCommissio n').value='0.00 ' ">
    ..
    ..
    <td><input type="text" class="textBox" name="potCommis sion" id="potCommissi on" size="10" value='<%=commi ssion%>'
    <% if(!commissionF lag.equals("NG" )){ %> disabled="true" <%}%> ></td>[/HTML]

    Comment

    • rsrinivasan
      New Member
      • Mar 2007
      • 221

      #3
      Originally posted by lavanyak6
      have written a code for textbox in jsp

      [HTML]<td><input type="text" class="textBox" name="potCommis sion" id="potCommissi on" size="10" value='<%=commi ssion%>'
      <% if(!commissionF lag.equals("NG" )){ %> disabled="true" <%}%> ></td>[/HTML]

      whenever the page loads the textbox contains the same value the user has typed in. I want it to be defaulted it to '0.00' whenever the page is refreshed. any inputs?
      Another method is you can set 0.00 as the default value in your form class.

      that is,
      In the form class
      .....
      .....
      private int potCommission = 0.00;
      ....
      .....

      getter/setter method.

      Comment

      • sumittyagi
        Recognized Expert New Member
        • Mar 2007
        • 202

        #4
        Originally posted by rsrinivasan
        Another method is you can set 0.00 as the default value in your form class.

        that is,
        In the form class
        .....
        .....
        private int potCommission = 0.00;
        ....
        .....

        getter/setter method.
        This wouldn't work when you refresh a page. As previous request is resubmitted when you refresh the page, so server will serve you the same result(as HTTP is a stateless protocol).

        Note: My solution is specifically for solving lavanyak6's question, and not the best practice to do, as some mechanism should be applied at server-side for preventing submittion of same request more than once due to refreshing the page.
        Again for some scenarios it doesn't matter, and for some, it does.

        Comment

        • RedSon
          Recognized Expert Expert
          • Jan 2007
          • 4980

          #5
          Please enclose your posted code in [code] tags (See How to Ask a Question).

          This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

          Please use [code] tags in future.

          acoder has taken care of it for you this time.

          MODERATOR

          Comment

          Working...