Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1504
  • Last Modified:

Asp - refresh data without posting form

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
mkuchy
Asked:
mkuchy
2 Solutions
 
SlimshaneeyCommented:
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
 
Shailesh15Commented:
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
 
zastilCommented:
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
alorentzCommented:
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
 
mkuchyAuthor Commented:
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
 
alorentzCommented:
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
 
mkuchyAuthor Commented:
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
 
alorentzCommented:
>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
 
mkuchyAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now