How to blank out a field before re-loading the page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rmurgia
    New Member
    • May 2008
    • 63

    How to blank out a field before re-loading the page

    Hello,

    I have a situation using VBScript where I read a table of valid serial numbers and if the serial number cannot be found, blank out the serial number field, display an error message, and reload the page. Listed below is some of the code which would be issued after the valid serial number table is read. ( The error message display is left off since that code is working.)

    Serial # field:
    Code:
    <input type="text" name="SerialNum" id="SerialNum" MaxLength="11"  value="<%=strSerialNum%>">
    Code used after valid serial number table read:
    Code:
    <%
    If rec.EOF Then  
      (Display Error Message Code here.)
      strSerialNum = "" 
    %>
    <script>
       window.location.reload(); 
     </script>
    <%
     End If
    %>
    Problem:
    The problem is that blanking out the variable strSerialnum is not blanking the SerialNum field and after the reload is issued (after a bad serial number is entered), the code at the top of the program:
    strSerialNum = Request.Form("S erialNum")
    reloads the bad serial number.

    I tried using the following before the reload:
    <script type="text/javascript">
    document.frmPPD M.SerialNum.val ue = "";
    </script>
    but got an error indicating a null object. Does anyone have any ideas, how to blank out the SerialNum field before doing the reload of the page?
    Last edited by jhardman; Mar 28 '10, 04:12 PM. Reason: added code tags. please use code tags in the future
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    I tried using the following before the reload:
    <script type="text/javascript">
    document.frmPPD M.SerialNum.val ue = "";
    </script>
    This is definitely the right approach, I'm not a Javascript expert, but i would bet your javascript syntax is slightly off. maybe something like getelementbyid, or document.all...

    Anyway, in your previous approach, you set the value of the input from the variable, then clear the variable and submit the form, but the form input still has the value set, that's why you need to do the javascript step to clear the form input. The other option would be to check for validity BEFORE you put the number in the form input.

    Jared

    Comment

    • rmurgia
      New Member
      • May 2008
      • 63

      #3
      Thanks for the response. I tried re-arranging a few lines of code and everything seems to be working.

      Comment

      Working...