Solved

Asp - refresh data without posting form

Posted on 2004-04-22
9
1,479 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 31

Assisted Solution

by:alorentz
alorentz earned 300 total points
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:mkuchy
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now