?
Solved

Asp - refresh data without posting form

Posted on 2004-04-22
9
Medium Priority
?
1,496 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 800 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Assisted Solution

by:alorentz
alorentz earned 1200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

719 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