keep the values when it redirect the same page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • accessman2
    New Member
    • Apr 2006
    • 3

    keep the values when it redirect the same page

    Hi,

    I have a question.

    I made the create the new user form.

    Code:
     <script language="javascript"> 
     
    function submitFrm()
    {
    document.submitform.action="complete.asp"
    document.submitform.submit();
    }
    function Validate()
    {
    var username = document.submitform.username.value;
    var password = document.submitform.password.value;
    var email = document.submitform.email.value;
    var str = ""
     
    if (username=="")
    {str="Username";}
    if (password=="")
    {str=str + "\nPassword";}
    if (email=="")
    {str=str + "\nE-Mail";}
     
    if (username=="" || password=="" || email=="")
    { alert("Please Fill out the following field:\n\n" + str);}
    else {return submitFrm();}
    }
    </script>
     
    <form name="submitform" method="post" action="" OnSubmit="Validate()">
    <center>
    <table border=2>
    <tr><td>First Name:</td><td><input type="text" name="fname" size="32" /></td></tr>
    <tr><td>Last Name:</td><td><input type="text" name="lname" size="32" /></td></tr>
    <tr><td>Sex:</td><td><input type="radio" name="sex" value="Male">Male</input>
    <input type="radio" name="sex" value="Female">Female</input></td></tr>
    <tr><td>Username:</td><td><input type="text" name="username" size="32" /></td></tr>
    <tr><td>Password:</td><td><input type="password" name="password" size="32" /></td></tr>
    <tr><td>E-Mail:</td><td><input type="text" name="email" size="32" /></td></tr>
    <tr><td></td><td><center><input type="submit" value="Submit" /><input type="reset" value="reset" /></center></td></tr>
    </table>
    <%
    if request.querystring("new")="exists" then
    Response.Write("Username already exists in database.")
    end if
    %>
    It works fine, but I want to keep back the Firstname, lastname, sex, and e-mail values. How can I keep the values once it redirect the newuser page.

    Because, if there is one invalide value, then it will redirect the same page and remove all values I input.

    How can I keep firstname, lastname, sex, and e-mail values?
    Thanks.
    Last edited by Niheel; Jul 27 '06, 05:50 AM.
  • meenu_susi
    New Member
    • Jun 2006
    • 47

    #2
    can u tell what u want to do ..
    whether u want to post the data to nextpage
    r else u want to check the use input data..
    tell me in detail...
    with regards
    meenu

    Comment

    • iam_clint
      Recognized Expert Top Contributor
      • Jul 2006
      • 1207

      #3
      Based on the title of this thread
      Code:
      <%
      dim name
      name = Request("name")
      %>
      First Name: <input type="text" value="<%=name%>">

      or have no actuall submit button take action and onsubmit out of the form and use a button instead of a submit button and use on click so when you click it, it validates then sends the information otherwise you will stay on the same page and the javascript should display the errors without any refreshing done.
      this will keep the values in the text field as the previous submitted form, if this wasn't what your are looking for then please rephrase your question.

      Comment

      • meenu_susi
        New Member
        • Jun 2006
        • 47

        #4
        hi...
        save the following code as html file and test it in your local server...

        <
        Code:
         html> 
        <head>
        <title>Untitled Document</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        </head>
        <SCRIPT LANGUAGE=javascript>
        function fndelete()
         
        {
        if (document.form.category.value=="")
        {
        alert("Please select values !");
        document.form.category.focus();
        return false;
        }
        if (document.form.sname.value=="")
        {
        alert("Content Field is Empty !");
        document.form.sname.focus();
        return false;
        }
        if (document.form.style.value=="")
        {
        alert("Content Field is Empty !");
        document.form.style.focus();
        return false;
        }
         
         
         
        if (document.form.price.value=="")
        {
        alert("Content Field is Empty !");
        document.form.price.focus();
        return false;
        }
        if (document.form.shpcost.value=="")
        {
        alert("Content Field is Empty !");
        document.form.shpcost.focus();
        return false;
        }
         
         
        return true;
        }
        </SCRIPT>
         
         
         
        <body bgcolor="#000000" text="#000000">
        <div align="center"> <p>&nbsp;</p><p><font color="#FF9900" size="3" face="Arial, Helvetica, sans-serif"><b>Tshirt 
        &nbsp;Entry</b></font></p>
         
        <form name="form" method=post action="insert.asp" onsubmit="return fndelete();"> 
        <table width="44%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="41%" height="25"> 
        <div align="left"><font color="#CCCCCC" face="Arial, Helvetica, sans-serif" size="2">Category</font></div></td><td width="59%" height="25"> 
        <font color="#CCCCCC" face="Arial, Helvetica, sans-serif" size="2">
         
        <SELECT NAME="category">
        <option value="cooltshirt">cooltshirt</option>
        <option value="funnytshirt">funnytshirt</option>
        <option>Beefy-T Youth</option>
        <option>Beefy-T Adult Long Sleeve </option>
        <option>Playwear Toddler</option>
        <option>Playwear Infant </option>
        <option>Playwear Infant Creeper</option>
        <option>Ultimate Crew Sweatshirt</option>
        <option>3/4 Sleeve Raglan </option>
        </SELECT></font></td></tr><TR> 
        <TD WIDTH="41%" HEIGHT="25"> <DIV ALIGN="left"><FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2">Name</FONT></DIV></TD><TD WIDTH="59%" HEIGHT="25"> 
        <FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2"> <INPUT TYPE="text" NAME="name"> 
        </FONT></TD></TR><TR> <TD WIDTH="41%" HEIGHT="25"> <DIV ALIGN="left"><FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2">Style</FONT></DIV></TD><TD WIDTH="59%" HEIGHT="25"> 
        <FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2"> <SELECT NAME="style"><OPTION>mens</OPTION><OPTION>womens</OPTION><OPTION>kids</OPTION></SELECT></FONT></TD></TR><TR> 
        <TD WIDTH="41%" HEIGHT="25"> <DIV ALIGN="left"><FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2">Color</FONT></DIV></TD><TD WIDTH="59%" HEIGHT="25"> 
        <FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2"> <INPUT TYPE="text" NAME="color"> 
        </FONT></TD></TR><TR> <TD WIDTH="41%" HEIGHT="25"> <DIV ALIGN="left"><FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2">Size</FONT></DIV></TD><TD WIDTH="59%" HEIGHT="25"> 
        <FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2"> <SELECT NAME="size">
        <option>S</option>
        <option>M</option>
        <option>L</option>
        <option>XL</option>
        <option>XXL</option>
        </SELECT></FONT></TD></TR><TR> 
        <TD WIDTH="41%" HEIGHT="25"> <DIV ALIGN="left"><FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2">Quantity</FONT></DIV></TD><TD WIDTH="59%" HEIGHT="25"> 
        <FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2"> <SELECT NAME="qty">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
        <option>6</option>
        <option>7</option>
        <option>8</option>
        <option>9</option>
        <option>10</option>
        </SELECT></FONT></TD></TR><TR> 
        <TD WIDTH="41%" HEIGHT="25"> <DIV ALIGN="left"><FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2">Price</FONT></DIV></TD><TD WIDTH="59%" HEIGHT="25"> 
        <FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2"> <INPUT TYPE="text" NAME="price"> 
        </FONT></TD></TR><TR> <TD WIDTH="41%" HEIGHT="25"> <DIV ALIGN="left"><FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2">ShippingCost</FONT></DIV></TD><TD WIDTH="59%" HEIGHT="25"> 
        <FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2"> <INPUT TYPE="text" NAME="shpcost"> 
        </FONT></TD></TR><TR> <TD WIDTH="41%" HEIGHT="25"> <DIV ALIGN="left"><FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2">Image</FONT></DIV></TD><TD WIDTH="59%" HEIGHT="25"> 
        <FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2"> <INPUT TYPE="file" NAME="image"></FONT></TD></TR><TR> 
        <TD WIDTH="41%" HEIGHT="25"> <DIV ALIGN="left"><FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2">Description</FONT></DIV></TD><TD WIDTH="59%" HEIGHT="25"> 
        <FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2"> <INPUT TYPE="text" NAME="descp"> 
        </FONT></TD></TR><TR> <TD WIDTH="41%" HEIGHT="25"> <DIV ALIGN="left"><FONT FACE="Arial, Helvetica, sans-serif" SIZE="2" COLOR="#CCCCCC">Pattern</FONT></DIV></TD><TD WIDTH="59%" HEIGHT="25"> 
        <FONT COLOR="#CCCCCC" FACE="Arial, Helvetica, sans-serif" SIZE="2"> <INPUT TYPE="text" NAME="pat"> 
        </FONT></TD></TR><tr><td colspan="2"><DIV ALIGN="CENTER"><FONT COLOR="red" SIZE="2" FACE="bolditalic"><B><FONT COLOR="red" SIZE="2" FACE="bolditalic"><INPUT TYPE="submit" NAME= "a2" VALUE="insert" SIZE="4"></FONT></B></FONT></DIV></td></tr> 
        </table></form><p>&nbsp;</p><p>s</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p></div>
        </body>
        </html>
        Last edited by Niheel; Jul 27 '06, 05:50 AM.

        Comment

        • Niheel
          Recognized Expert Moderator Top Contributor
          • Jul 2005
          • 2432

          #5
          Meenu,

          Use the code tags , the " # " button to store code. Otherwise it disorts the page.

          - KUB
          niheel @ bytes

          Comment

          • meenu_susi
            New Member
            • Jun 2006
            • 47

            #6
            hi KUB


            how to do that...
            i am new to this forum..
            can u tell me how to do..

            Comment

            Working...