Solved

onchange pass values back to form reload.

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Date on a table 16 35
Jquery driving me nuts... 14 28
Put POST values into cookies. 14 34
center navbar (navigation menu) on web page 3 22
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

733 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