Solved

Asp - refresh data without posting form

Posted on 2004-04-22
9
1,483 Views
Last Modified: 2012-05-04
I have a form that updates a database. The form action is post to update the database.   I have several dependent dropboxes for selection.  When a new value is selected for the first dropbox, I want to change the values in the second dropbox. Then I want to continue processing the form from the next field - not the start of page.  I have tried to do a submit to self onchange of a field but instead of starting the page with the new selection data, the form does the update of the database even though the form may not be completed yet.  Is there a way to submit the form to itself to refresh the data and start the page processing from where they left off?  If I put the focus on the next field in form, will the logic for the preceding fields still be executed?
0
Comment
Question by:mkuchy
9 Comments
 
LVL 11

Expert Comment

by:Slimshaneey
ID: 10889545
Why not have the selects in your page merely do a document.location.href='thispage.asp?val1=" + selectval, and do that for each select adding each select val to the queryastring, that way you havent posted any data. Then when the person is done with the select he hits the submit button which submits the form
0
 
LVL 10

Accepted Solution

by:
Shailesh15 earned 200 total points
ID: 10890164
What you are asking is can be done. But you need to post the code.

Here is the logic...
keep a hidden field which keeps the state of the form.
On submit event have a function  which evaulates the form status by checking values. Hidden state field is updated for the type of action you want your ASP to handle. like 'update'.
In ASP before update  check for the value of state in request.form collection.
0
 
LVL 3

Expert Comment

by:zastil
ID: 10890439
Not sure why your form is updating your database unless you doing onchange="frm.submit()"?

Use document.location.href='page.asp?selVal='+this.value


0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 31

Assisted Solution

by:alorentz
alorentz earned 300 total points
ID: 10893290
You are doing it right, but surrund your database update code in an If Statement:

If request("submit") = "Submit" then
   'update the DB
end if

And on your form use a submit button:

<input type=submit value="Submit" name=submit>


So it only update the DB when you submit the form.  Just posting to itelf ONCHANGE will not update the DB that way...
0
 

Author Comment

by:mkuchy
ID: 10902899
I think I need to clarify my problem a bit more and show my code so here goes:

My page has multiple dropboxes which get the initial default values from a querystring sent from previous page.  Since each suceeding dropbox is dependent on prior dropbox select value - I need to be able to change option values for each box based on prior box. At the time all fields have been filled out, user presses submit to update database.  So my problems have been twofold.  If a dropbox select is changed - I want to clear existing value in dependent dropbox & reload appropriate options.  I am trying to accomplish this by doing following: example- for 1st dropbox - onchange, post form to self with new values.  I do not want to do update at this point - submit was not used, I did an auto submit to self.  Also, I need to make sure that if user goes back and changes a prior box, any dependent boxes are cleared and reloaded.  Am I being totally confusing? Code is below:
 *loads initial values by doing select based on querystring if 1st time through or form if not

If Request.Form ("empn") = "" then
  SQL ="SELECT * FROM schedule where id =" &Request.QueryString("id")
  rs.Open SQL, my_Conn
        dt = rs("shift_dte")
        shiftsel = rs("shiftID")
        etim = rs("shiftEnd")
        stim = rs("shiftBegin")
         person = rs("shiftPerson")
        empn = rs("shiftPerson") & "|" & rs("EType")
        site = rs("SiteName")
else
        site = Request.Form("site")
        person = Request.Form("empn")
        empn = Request.Form("empn")
        shiftsel = Request.Form("shiftsel")
        etim = Request.Form("etim")
        stim = Request.Form("stim")
 end if

<form action="sched_edit.asp?mode=DoEdit" method=post name=thefrm>
 <select name="empn" onchange="javascript:refreshpg();">
<%  
      set rsemp = Server.CreateObject("ADODB.Recordset")
      strSQL = "SELECT DISTINCT empID, empName, empType FROM Employees ORDER BY empName"
      rsemp.Open strSQL, my_conn
      Response.Write "<option value=1>Select...</option>"
                do until rsemp.EOF
                 If rsemp("empName") = person then
                       Response.Write "<option value='" &rsemp("empName")& "|" & rsemp("empType") & "' Selected>"  &_
             rsemp("empName")  &  "</option>" & vbcrlf
      else      
            Response.Write "<option value='"
            Response.Write rsemp("empName") &"|"& rsemp("empType")& "'"
           Response.Write ">"  & rsemp("empName") &"</option>" & vbcrlf
      end if
            rsemp.MoveNext
      loop
      rsemp.Close
      set rsemp=nothing

%>

  </select>
<%
   wname = empn
   nsplit = split(wname, "|")
  %>
  <input TYPE="hidden" NAME="person" value="<%=nsplit(0)%>">
  <iinput TYPE="hidden" NAME="etype" VALUE="<%=nsplit(1)%>">

the script for any onchange is
function refreshpg() {  
    history.go(-1);
    document.thefrm.submit();

the next dropboxes use selected values from prior to load options....
so if the value in any box changes - I want to post page back to itself and go through all logic again, clearing dependent values to make sure values selected are appropriate for preceding dropbox.  What's happening is onchange doesn't work and the page goes through the update process instead of refreshing page with new data and continuing till submit button clicked.  Does this make any sense to anyone????
0
 
LVL 31

Expert Comment

by:alorentz
ID: 10902962
The answer I gave earlier does just that...have you tried it?  It only submits when they click submit..
 
Maybe I don't get what you want?
0
 

Author Comment

by:mkuchy
ID: 10907792
I did try your suggestion - worked only partially.It no longer does update unless submit selected - but the refresh of data still doesn't work which is critical.  Can you see a problem with the onchange function?
0
 
LVL 31

Expert Comment

by:alorentz
ID: 10907911
>but the refresh of data still doesn't work which is critical

What do you means?  

Also, I don't think the history.go(-1) is necessary...all that is happening is postsing the same information, over and over again...
0
 

Author Comment

by:mkuchy
ID: 10909777
I took the history.go(-1) out.  What I mean by critical is that the function refreshpg doesn't work - isn't being executed therefore the new selections for dependent boxes never gets passed.  Can you see anything wrong?
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to update a dummy recordset with classic ASP 4 85
Forcing form refresh - classic ASP 7 65
Summernote required 3 137
Using querystring in a hyperlink 3 50
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question