Solved

onchange pass values back to form reload.

Posted on 2007-03-22
4
279 Views
Last Modified: 2010-04-16
Hi all,
As much as my skills have increased in web desing and such, some things are still beyond me.

I have a web page with a single form.  This form will have a single submit button.  On the form is a <select onchange> that summons up the following Jscript:

    function reload(form){
    var val=form.dept.options[form.dept.options.selectedIndex].value;
    self.location='preprint.asp?dept=' + val;
    }
I can then use "IF not dept = "" then" to process the creation of a new <select>...  

This part works great.  The problem is that all other fields in the form are erased when the onchange script is called.  I need the onchange to also pass through the user entries from a variety of text fields and radio buttons and repopulate the form, with the new dropdown menu and all the previously entered text fields.

How do I modify the form, or the script so that I can do this:

    self.location='preprint.asp?dept=' + val + '&val2=' + val2 + '&val3=' +val3;

Thanks!
0
Comment
Question by:Ranidae
  • 3
4 Comments
 
LVL 11

Expert Comment

by:flipz
ID: 18773629
I assume that the selected option (dept) will dictate which values are loaded into another drop-down? Is that correct. I think the preferred method would be to use an AJAX call to retrieve only the information you need and populate the new drop-down without reloading the entire page. Can you post more of you code and tell what fields are to be populated when the dept value is selected?
0
 
LVL 2

Author Comment

by:Ranidae
ID: 18773785
Here is the basic code, the strOctX values need to be maintaned.  More select options wil be added as queried from the same db with other information threads that need to be completed by the user.

<SCRIPT language=JavaScript>
    function reload(form){
    var val=form.dept.options[form.dept.options.selectedIndex].value;
    self.location='preprint.asp?dept=' + val;
    }
</script>
 dept=Request.QueryString("dept")

  Set Cnn = Server.CreateObject("ADODB.Connection")
  Cnn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=D:\Web_Tools\printer_management.mdb"

   If len(dept) > 1 Then
        selectLocName = "Select * from printer_locations where location_id = '" & dept & "'"
        set objLoc = cnn.Execute(selectLocName)
        strLocationName = objLoc("location_name")
   End If

%>

        <form method=post name=f1 action=''>
            Identify the subnet where the printer will reside.
            <input type="text" size="1" maxlength="3" name="strOct1"/><b> . </b>
            <input type="text" size="1" maxlength="3" name="strOct2"/><b> . </b>
            <input type="text" size="1" maxlength="3" name="strOct3"/><b> . </b>
            <input type="text" size="1" maxlength="3" name="strOct4" value="0"/>
   
           Identify the Printer Location
            <%
            if strLocationName = "" then
                strtmpLocationName = "Select Location"
            else
                strtmpLocationName = strLocationName
            End IF
           
            selectsql = "SELECT * FROM printer_locations"
            Set objRS = Cnn.Execute(selectSQL)
           
            response.Write "<select name=dept onchange='reload(this.form)'><option value=''>" & strtmpLocationName & "</option>"
            Do while not objRS.EOF
                Response.Write "<option value=" & objRS("location_id") & ">" & objRS("location_name") & "</option>"
                objRS.movenext
            loop
           
            response.Write "</select> "
            objRS.close
                       
            If len(dept) > 1 Then
                        response.Write " <select name=floor><option value=''>Floor</option>"
                strSQL = "SELECT * FROM location_floors where floor_location='" & dept &"'"
                set objRS = Cnn.Execute(strSQL)
                response.Write strSQL
             
                Do While Not objRS.EOF
                    Response.Write "<option value = " & objRS("floors_areas") & ">" & objRS("floors_areas") & "</option>"
                    objRS.MoveNext
                Loop
               
                response.Write "</select>"
                objRS.Close
            end if
            Cnn.Close
            %>
      </form>
0
 
LVL 11

Accepted Solution

by:
flipz earned 500 total points
ID: 18773843
If it is just the 'Oct' values that need to be retained - try this:

<SCRIPT language=JavaScript>
    function reload(form){
    var val=form.dept.options[form.dept.options.selectedIndex].value;
    var strURL = 'preprint.asp?dept=' + val + '&val2=' + f1.strOct1.value + '&val3=' +f1.strOct2.value + '&val4=' +f1.strOct3.value + '&val5=' +f1.strOct4.value;
    self.location='preprint.asp?dept=' + val;
    }
</script>
 dept=Request.QueryString("dept")

  Set Cnn = Server.CreateObject("ADODB.Connection")
  Cnn.open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=D:\Web_Tools\printer_management.mdb"

   If len(dept) > 1 Then
        selectLocName = "Select * from printer_locations where location_id = '" & dept & "'"
        set objLoc = cnn.Execute(selectLocName)
        strLocationName = objLoc("location_name")
   End If

%>

        <form method=post name=f1 action=''>
            Identify the subnet where the printer will reside.
            <input type="text" size="1" maxlength="3" name="strOct1" value="<%=Request.Querystring("val2")%>"/><b> . </b>
            <input type="text" size="1" maxlength="3" name="strOct2" value="<%=Request.Querystring("val3")%>"/><b> . </b>
            <input type="text" size="1" maxlength="3" name="strOct3" value="<%=Request.Querystring("val4")%>"/><b> . </b>
    <% strOct4 = "0"
   if Len(Request.Querystring("val5")) > 0 then
       strOct4 = Request.Querystring("val5")
   end if
            <input type="text" size="1" maxlength="3" name="strOct4" value="<%=strOct4%>"/>
   
           Identify the Printer Location
            <%
            if strLocationName = "" then
                strtmpLocationName = "Select Location"
            else
                strtmpLocationName = strLocationName
            End IF
           
            selectsql = "SELECT * FROM printer_locations"
            Set objRS = Cnn.Execute(selectSQL)
           
            response.Write "<select name=dept onchange='reload(this.form)'><option value=''>" & strtmpLocationName & "</option>"
            Do while not objRS.EOF
                Response.Write "<option value=" & objRS("location_id") & ">" & objRS("location_name") & "</option>"
                objRS.movenext
            loop
           
            response.Write "</select> "
            objRS.close
                       
            If len(dept) > 1 Then
                        response.Write " <select name=floor><option value=''>Floor</option>"
                strSQL = "SELECT * FROM location_floors where floor_location='" & dept &"'"
                set objRS = Cnn.Execute(strSQL)
                response.Write strSQL
             
                Do While Not objRS.EOF
                    Response.Write "<option value = " & objRS("floors_areas") & ">" & objRS("floors_areas") & "</option>"
                    objRS.MoveNext
                Loop
               
                response.Write "</select>"
                objRS.Close
            end if
            Cnn.Close
            %>
      </form>
0
 
LVL 11

Expert Comment

by:flipz
ID: 18773848
Forgot close script tags here:

<% strOct4 = "0"
   if Len(Request.Querystring("val5")) > 0 then
       strOct4 = Request.Querystring("val5")
   end if     'close the script!! %>
            <input type="text" size="1" maxlength="3" name="strOct4" value="<%=strOct4%>"/>
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 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

20 Experts available now in Live!

Get 1:1 Help Now