Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

asp and html form

  • 10-07-2007 01:48PM
    #1
    Registered Users, Registered Users 2 Posts: 36


    I am trying to display the old varible in the text field and after the user changes the varible in the text field, the new varible will display here

    please look at my code:

    <html>
    <body>
    <form action="a.asp" method="post">
    Your name: <input type="text" name="fname" size="20" value="<% response.Write(fname) %>" />
    <input type="submit" value="Submit" />
    </form>
    <%
    session fname
    fname=Request.Form("fname")
    If fname<>"" Then
    Response.Write("Hello " & fname & "!<br />")
    Response.Write("How are you today?")
    End If
    %>
    </body>
    </html>:confused:


Comments

  • Registered Users, Registered Users 2 Posts: 273 ✭✭stipey


    Without doing all the work for you... it looks like when you write the value into the textfield there is nothing there.

    This is because the value is empty.

    Why is it empty?


  • Registered Users, Registered Users 2 Posts: 4,468 ✭✭✭matt-dublin


    your codes back to front...

    you need to create the session at the top of the page
    code wrote:
    <html>
    <%session fname
    fname=Request.Form("fname")
    %>
    <head></head>
    <body>
    <form action="a.asp" method="post">
    Your name: <input type="text" name="fname" size="20" value="<% response.Write(fname) %>" />
    <input type="submit" value="Submit" />
    </form>
    <%
    If fname<>"" Then
    Response.Write("Hello " & fname & "!<br />")
    Response.Write("How are you today?")
    End If
    %>
    </body>
    </html>


  • Registered Users, Registered Users 2 Posts: 36 or89


    thats lookin good, thanks for the time and help


  • Registered Users, Registered Users 2 Posts: 4,468 ✭✭✭matt-dublin


    also i think it should be...
    code wrote:
    <%
    if request.form("fname") <> "" then
    session("fname")= Request.Form("fname")
    end if
    %>

    for an actual session

    what you've done there is just create a string

    so the rest of your code would look like as follows:
    code wrote:
    <%
    If fname<>"" Then%>
    Hello <%=session("fname")%>!<br />
    How are you today?
    <%
    End If
    %>

    and like this:
    code wrote:
    <form action="a.asp" method="post">
    Your name: <input type="text" name="fname" size="20" value="<%=server.htmlencode(session("fname"))%>" />
    <input type="submit" value="Submit" />
    </form>


Advertisement