Solved

onchange pass values back to form reload.

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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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 …

691 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