Solved

onchange pass values back to form reload.

Posted on 2007-03-22
4
282 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
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.

770 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