Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 6th, 2006, 11:23 AM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default SOS Retain values on SubmitText field and DropDown

Posted - 03/06/2006 : 2:35:35 PM


--------------------------------------------------------------------------------

I have a page split up into different forms. I have the top most which has a text field and a dropdown menu (in which there are 2 values coming from two different tables) Next to the dropdown list is a submit button, which on clicking will retrieve some data with checkboxes at the bottom of the page.
My problem is I cannot retain what the user entered in the report name and what was chosen in the dropdown after clicking on the SUBMIT button.
I CAN retrieve the values in the variables at the bottom of the code AFTER clicking on Submit. My only problem is how do I retain them in the text field and dropdownlist.
================================================== ===================

 <form name="Report_Drive" action="pop_results_page.asp" method="GET" onsubmit="return Form1_Validator(this)">
<table border="0" width="100%" cellpadding="5" cellspacing="5">
    <tr>
        <td width="40%" align="left">
    Enter Report Name



<input type="text" size=62 name="report_name" style="top: 30px; left: 393px; width: 180px" maxlength=150 id=report_name value=<%Request.QueryString("report_name")%>>
    </td>

    <td width="60%" align="left">

    Choose a Drive Period from the list
    <select ID="drive" name="drive" language="javascript" onchange="return drive_onchange(Results_Report)">
    <option id=0 value=0>Select a new Drive Period...</option>


            <%

            set rst=Server.CreateObject("adodb.recordset")
            strSQL = "SELECT * FROM POPD_FY_DRIVE"
            rst.Open strSQL,conn

            Do while not rst.eof

                if rst("FY_DRIVE_ID") = Request.Form("drive") then

                    Response.Write("<option value=" & rst("FY_DRIVE_ID") &"SELECTED>" )
                    Response.Write (rst("YEAR_KEY")& " " & rst("YEAR_DRIVE_DESC") & "</option>" )
                else
                    Response.Write("<option value=" & rst("FY_DRIVE_ID") &">" )
                    Response.Write (rst("YEAR_KEY")& " " & rst("YEAR_DRIVE_DESC") & "</option>" )

                    rst.MoveNext
                end if
            Loop
            rst.close%>
            </select>


    <input type="submit" name="RetrieveSKUs" value="RetrieveSKUs" onclick="Javascript:retain();">
    </tr>
</form>

<% dim tempname
    tempname=Request.QueryString("report_name")
    Response.Write("Hello - you chose Report Name: " & tempname )
    session("report_name") = tempname
    %>
    <br>
    <%
    dim tempdrive
    tempdrive=Request.QueryString("drive")
    Response.Write("Hello - you chose drive: " & tempdrive )
    session("drive") = tempdrive
    %>




Reply With Quote
  #2 (permalink)  
Old March 6th, 2006, 06:58 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

This is how I do it:
---------------cut n paste------------------
<% if not rst.Eof %>
        <select ID="drive" name="drive" language="javascript" onchange="return drive_onchange(Results_Report)">
         <option id=0 value=0>Select a new Drive Period...</option>
<% do while not rst.Eof %>
           <option value="<%= rst("FY_DRIVE_ID") %>" <% if (cint(rst("FY_DRIVE_ID")) = cint(Request.Form("drive"))) then response.write " selected " end if %>> <%= rst("YEAR_KEY")& " " & rst("YEAR_DRIVE_DESC") %> </option>
<% rst.moveNext
        loop %>
        <select>
<% else %>
        <i>No data found</i>
<% end if %>
--------------------------------------------

A couple of points:

1..Are the two values you are comparing integers:
   (rst("FY_DRIVE_ID")
and
   Request.Form("drive")
if so you should run the CINT function around them (as I have done in the example)

2.. what if your record set is empty? You should include a 'if not rst.Eof' in addition to what you have (as I have done) This way you wont print a empty select box to the browser if your recors set is empty. You may say it never will be, why take the risk? IMO this is a bad habbit.

3..This line here:
Response.Write("<option value=" & rst("FY_DRIVE_ID") &"SELECTED>" )
You need to have a space inside your option tag between the value property and the word selected (making this change and the change in point 1 will probably make your code work).


Wind is your friend
Matt
Reply With Quote
  #3 (permalink)  
Old March 6th, 2006, 11:18 PM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mat41,

Firstly, thank you for your prompt reply. However, its still not retaining the values for some reason.
So, I stripped the code to the following (I do plan to handle the exception if the result set is empty):
================================================== ===================
<%
set rst=Server.CreateObject("adodb.recordset")
strSQL = "SELECT * FROM POPD_FY_DRIVE"
Set rst=conn.execute(strSQL,,1)
%>

<select ID="drive" name="drive" language="javascript" onchange="return drive_onchange(Results_Report)">

<option id=0 value=0>Select a new Drive Period...</option>
<% do while not rst.Eof %>
<option value="<%= rst("FY_DRIVE_ID") %>"
<% if (cint(rst("FY_DRIVE_ID")) = cint(Request.Form("drive"))) then response.write " selected " end if %>> <%= rst("YEAR_KEY")& " " & rst("YEAR_DRIVE_DESC") %>
</option>
<% rst.moveNext
loop %>
</select>
================================================== ===================

1. Yes, they're both integers. 'drive' being the id for the value selected.

2. Will add for those cases.

3. Tired that, still doesn't stick.

I am very sure the Form, after getting submitted, is getting the correct text entered in the textfield box and the id for the Drive period selected, because I am printing those out after storing them in a variable.

Do you also have any suggestions for how to retain value in the text field?

Reply With Quote
  #4 (permalink)  
Old March 6th, 2006, 11:35 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

mmmmmm, youre code looks ok to me - I do believe there are no syntax errors (you are not getting errors are you?)

To resolve change this line:
<% if (cint(rst("FY_DRIVE_ID")) = cint(Request.Form("drive"))) then response.write " selected " end if %>> <%= rst("YEAR_KEY")& " " & rst("YEAR_DRIVE_DESC") %>

to:
<% if (cint(rst("FY_DRIVE_ID")) = cint(Request.Form("drive"))) then response.write " selected " end if %>> <%= rst("YEAR_KEY")& " " & rst("YEAR_DRIVE_DESC") & " :DBValue=" & rst("FY_DRIVE_ID") & " - formValue=" & Request.Form("drive") %>

What I have done is print the two values iside the select area. Now we can physically compare them. Post the rendered HTML here and let me see what you see. If they are the same, they have the cInt function around them the item will remain selected.

;;;2. Will add for those cases.
I am not sure wnat you are refering to ?

;;;I am very sure the Form, after getting submitted, is getting the correct text entered in the textfield box
What does a text area (or any other form element) have to do with the two values you are comparing in the problematic <select> area.

;;;and the id for the Drive period selected
Are you running some vaidation (JS) to ensure a selection has been made? Run that line above, post the code I asked for and we will see.

;;Do you also have any suggestions for how to retain value in the text field?
The method you are using is the method to use.

Wind is your friend
Matt
Reply With Quote
  #5 (permalink)  
Old March 6th, 2006, 11:40 PM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Also, on selecting the Drive Period from the dropdown list, I get an error on IE (Done !) and is pointing to the following javascript function:

function drive_onchange(Results_Report){


  document.Results_Report.drive.submit();
}

Error is pointing to 'drive' in the above function...is null or not an object.

Reply With Quote
  #6 (permalink)  
Old March 6th, 2006, 11:48 PM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Those were answers/replies to your qs in the first post.

Here's what I got in the dropdown menu:

Choose a Drive Period from the list&nbsp;


<select ID="drive" name="drive" language="javascript" onchange="return drive_onchange(Results_Report)">

<option id=0 value=0>Select a new Drive Period...</option>

<option value="4" > 2005 Disco 80s :DBValue=4 - formValue=2005 Disco 80s </option>

<option value="5" > 2004 * :DBValue=5 - formValue=2004 * </option>

<option value="6" > 2001 rfefsdfsd :DBValue=6 - formValue=2001 rfefsdfsd </option>

<option value="7" > 2001 sdsad :DBValue=7 - formValue=2001 sdsad </option>

<option value="8" > 2005 Wavy Fringes :DBValue=8 - formValue=2005 Wavy Fringes </option>

<option value="9" > 2005 Spring-Summer Drive :DBValue=9 - formValue=2005 Spring-Summer Drive </option>

<option value="10" > 2005 Trying a new drive :DBValue=10 - formValue=2005 Trying a new drive </option>

<option value="11" > 2006 New Years Logic String :DBValue=11 - formValue=2006 New Years Logic String </option>

<option value="12" > 2002 test :DBValue=12 - formValue=2002 test </option>

<option value="13" > 2005 Cannon Drive :DBValue=13 - formValue=2005 Cannon Drive </option>

<option value="14" > 2006 TRIAL DRIVE :DBValue=14 - formValue=2006 TRIAL DRIVE </option>

<option value="15" > 2003 hELLO :DBValue=15 - formValue=2003 hELLO </option>

</select>

Reply With Quote
  #7 (permalink)  
Old March 6th, 2006, 11:58 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Firstly get rid of Drive from your JS function:
Change:
document.Results_Report.drive.submit();
To:
Results_Report.submit();
NOTE: is Results_Report your form name?

Secondly can you not see what you are comparing? lets look at the first three:
;;;<option value="4" > 2005 Disco 80s :DBValue=4 - formValue=2005 Disco 80s </option>
4 does not match 2005

<option value="5" > 2004 * :DBValue=5 - formValue=2004 * </option>
5 does not match 2006

<option value="6" > 2001 rfefsdfsd :DBValue=6 - formValue=2001 rfefsdfsd </option>
6 does not match 2001


None of your values match therefore your condition will never evaulate to true. What option tag do you think should remain selected from your post?



Wind is your friend
Matt
Reply With Quote
  #8 (permalink)  
Old March 7th, 2006, 12:40 AM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

;;;OK, so how do I solve the problem?

Is your JS error fixed. It doesnt matter what tables the data is coming from. do you agree:
4 does not match 2005
5 does not match 2006
etc...

Therefore you havnt got as problem. you need to compare matching values to get your selections to hold.

If I select the first option:
<option value="4" > 2005 Disco 80s :DBValue=4 - formValue=2005 Disco 80s </option>
the value 4 should be inside the form variable "drive" - why does it hold 2005? (DBValue=4 - formValue=2005 | 4 does not equal 2005) Where is your value being chnaged? Place Request.Form("drive") in your page in several places what is the value? Where does it get changed, why does it get chnaged?

Wind is your friend
Matt
Reply With Quote
  #9 (permalink)  
Old March 7th, 2006, 12:53 AM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I see. Since, I need the FY_DRIVE_ID for the option I picked, later in the code. Can I do this? This does need some tweaking...

<select ID="drive" name="drive" language="javascript" onchange="return drive_onchange(Report_Drive)">

<option id=0 value=0>Select a new Drive Period...</option>
<% do while not rst.Eof %>
<option value="<%= rst("FY_DRIVE_ID") %>"
<% if (Request.Form("drive")= (rst("YEAR_KEY")& " " & rst("YEAR_DRIVE_DESC"))) then response.write " selected " end if %>> <%= rst("YEAR_KEY")& " " & rst("YEAR_DRIVE_DESC") %>
</option>
            <% rst.moveNext
        loop %>
        </select>

Reply With Quote
  #10 (permalink)  
Old March 7th, 2006, 01:08 AM
Authorized User
 
Join Date: Mar 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Nope, the JS function is still giving an error. Here is what I have:

function drive_onchange(Report_Drive){

  Report_Drive.Submit();
}

//more code here

 <form name="Report_Drive" action="pop_results_page.asp" method="GET" onsubmit="return Form1_Validator(this)">
<table border="0" width="100%" cellpadding="5" cellspacing="5">
    <tr>
        <td width="40%" align="left">
    Enter Report Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" size=62 name="report_name" style="top: 30px; left: 393px; width: 180px" maxlength=150 id=report_name value=<%Request.QueryString("report_name")%>>


    </td>

    <td width="60%" align="left">

    Choose a Drive Period from the list&nbsp;

            <%
                    set rst=Server.CreateObject("adodb.recordset")
                    strSQL = "SELECT * FROM POPD_FY_DRIVE"
                    Set rst=conn.execute(strSQL,,1)
            %>

        <select ID="drive" name="drive" language="javascript" onchange="return drive_onchange(Report_Drive)">

        <option id=0 value=0>Select a new Drive Period...</option>
            <% do while not rst.Eof %>
            <option value="<%= rst("FY_DRIVE_ID")%>"
            <% if ((rst("YEAR_KEY")& " " & rst("YEAR_DRIVE_DESC"))=Request.Form("drive")) then response.write " selected " end if %>> <%= rst("YEAR_KEY")& " " & rst("YEAR_DRIVE_DESC") %>
            </option>
            <% rst.moveNext
        loop %>
        </select>



    &nbsp;&nbsp;
    <input type="submit" name="RetrieveSKUs" value="RetrieveSKUs">
    </tr>
</form>

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to retain values of dynamic controls when page fozia_izhar .NET Framework 1.x 1 February 7th, 2007 02:32 PM
How to retain form values from dependent list ? George B Javascript 0 September 15th, 2006 03:54 PM
SOS: Retain values on Submit in Textfield,Dropdown rabbit124 Classic ASP Professional 1 March 7th, 2006 07:12 PM
Retain form values qhong Javascript 1 May 13th, 2004 02:02 AM



All times are GMT -4. The time now is 01:47 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.