?
Solved

onchange pass values back to form reload.

Posted on 2007-03-22
4
Medium Priority
?
297 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
[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
  • 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

752 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