Why is the dropdown list selection not updating form?

Here's my code, I have this working fine when I select the submit button but for some reason it is not submitting when I select an item from the drop down list.

<SCRIPT LANGUAGE=javascript>
<!--

function submitCountry(){
     var objForm = document.forms[0];
     objForm.elements['State'].selectedIndex=0;  'was region
     objForm.submit();
}
function submitState(){
     var objForm = document.forms[0];
     objForm.submit();
}

//-->
</SCRIPT>

</HEAD>
<BODY>
<FORM action="mypage.asp" method=POST id=form1 name=form1>
<SELECT  name="Country" onChange="submitCountry()">
    <%call  makeCountry%>
</SELECT><br>
<SELECT  name="State" onChange="submitState()">
    <%call makeState%>
</SELECT><br>
<p><INPUT type="submit" value="Submit" id=submit1 name=submit1></p>
</FORM>
</BODY>

Thanks
Chris_GrangerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ap_sajithCommented:
What do you mean not submitting?? Try the following code...

<SCRIPT LANGUAGE=javascript>
<!--

function submitCountry(){
    var objForm = document.forms[0];
    objForm.elements['State'].selectedIndex=0;  //was region
    objForm.submit();
}
function submitState(){
    var objForm = document.forms[0];
    objForm.submit();
}

//-->
</SCRIPT>

</HEAD>
<BODY>
<FORM action="test.asp" method=POST id=form1 name=form1>
<SELECT  name="Country" onChange="submitCountry()">
   <OPTION>CANADA</OPTION>
   <OPTION>US</OPTION>
   <OPTION>UK</OPTION>
   <OPTION>UAE</OPTION>
</SELECT><br>
<SELECT  name="State" onChange="submitState()">
   <OPTION>ABC</OPTION>
   <OPTION>DEF</OPTION>
   <OPTION>GHI</OPTION>
</SELECT><br>
<p><INPUT type="submit" value="Submit" id=submit1 name=submit1></p>
</FORM>
</BODY>

Cheers!!
0
Chris_GrangerAuthor Commented:
Great thanks for this. I think it was just a stupid mistake on my part. Problemo solved. Would love to ask a couple more questions but I guess I should close this and startup a new question., not really sure of ettiquette here. Let me know, if you want to solve the two questions below I'll double the points, otherwise I'll give you the 125 and repost new question...

FYI: Questions will be.
1. Using the working sample above, how do I actually post the form to another page when I wish to?
2. If there are other fields in the form, how do I capture and add these to the form each time it is updated via the selection of country?

Many Thanks
0
ap_sajithCommented:
Go through the script posted below. It shows you how to capture data and to post to pages dynamically..

<SCRIPT LANGUAGE=javascript>
<!--
function submitForm(bType)
{
//bType can take in True or False//
if (bType){
document.frmCountry.action='test1.asp'}
else{
document.frmCountry.action='test.asp'}
// Submit the form to the chosen page//
document.frmCountry.submit()
}

function submitCountry(){
document.frmCountry.hidValueToCapture.value=document.frmCountry.Country.options[document.frmCountry.Country.selectedIndex].value;
alert(document.frmCountry.hidValueToCapture.value);
submitForm(true);
}
function submitState(){
document.frmCountry.hidValueToCapture.value=document.frmCountry.State.options[document.frmCountry.State.selectedIndex].value;
submitForm(false);
}

//-->
</SCRIPT>

</HEAD>
<BODY>
<FORM method=POST id=frmCountry name=frmCountry>
<SELECT  name="Country" onChange="submitCountry()">
   <OPTION VALUE=CANADA>CANADA</OPTION>
   <OPTION VALUE=US>US</OPTION>
   <OPTION VALUE=UK>UK</OPTION>
   <OPTION VALUE=UAE>UAE</OPTION>
</SELECT><br>
<SELECT  name="State" onChange="submitState()">
   <OPTION Value=ABC>ABC</OPTION>
   <OPTION Value=DEF>DEF</OPTION>
   <OPTION Value=GHI>GHI</OPTION>
</SELECT><br>
<p>
<INPUT type="hidden" value="" id=hidValueToCapture name=hidValueToCapture>
<INPUT type="button" value="Submit" id=bSubmit name=bSubmit onclick="submitForm();"></p>
</FORM>
</BODY>

Cheers!!
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Chris_GrangerAuthor Commented:
That is fantastic, a million thankyous.  :-)  Just wondering, as far as capturing and reloading (when it posts to itself), how is this done with a standard text field with user input, such as:
<input name="firstname" type="text" size="25" maxlength="25" value="">

Cheers
0
ap_sajithCommented:
In an asp page, you can use the request.form method to capture the form data..

eg:

<input name="firstname" type="text" size="25" maxlength="25" value="<%=Request.Form("firstname")%>">

Cheers!!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fritz_the_blankCommented:
An additional comment here. I am pretty sure that the code in the orginal question came from a post that I had made in the past to show how to have multiple dependant selects. The problems you have are resulting from not working with the complete set of code. I am including it here for reference (it was designed to be tested with the Northwind database:



<%@ Language = VBScript %>
<%Option Explicit%>
<%Response.Buffer = True%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<%
dim  strDataPath, strConnectString, objConnection, strCountry, strRegion, strCity, objRS, strSelected

'set connection strings for entire application
strDataPath = server.MapPath("NorthWind.mdb")
strConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;"_
                  + " Data Source= " & strDataPath & ";"_
                  + " Mode=Share Deny None;User Id=admin;PASSWORD=;"
                  
if not IsObject("ojbConnection") then
      set objConnection=Server.CreateObject("ADODB.Connection")
      objConnection.ConnectionTimeout = 15
      objConnection.CommandTimeout =  10
      objConnection.Mode = 3 'adModeReadWrite
      if objConnection.state = 0 then
            objConnection.Open strConnectString
      end if
end if

strCountry = Request.Form("Country")
strRegion = Request.Form("Region")
strCity = Request.Form("City")

sub makeCountry()
      if not isObject("objRS") then
            set objRS=Server.CreateObject("ADODB.RecordSet")
      end if
      if objRS.state <> 0 then
            objRS.close
      end if
      objRS.Open "SELECT DISTINCT Country  FROM Customers ORDER BY Country",objConnection,3,3
      Response.Write("<option></option>" & VBCRLF )
      do while not objRS.EOF
            if objRS("Country") = strCountry then
                  strSelected = " Selected "
            else
                  strSelected = ""
            end if
            Response.Write("<option" & strSelected & ">" & objRS("Country") & "</option>" & VBCRLF )
            objRS.MoveNext
      loop
      objRS.Close
      set objRS=Nothing
end sub

sub makeRegion()
      if strCountry <> "" then
            if not isObject("objRS") then
                  set objRS=Server.CreateObject("ADODB.RecordSet")
            end if
            if objRS.state <> 0 then
                  objRS.close
            end if
            objRS.Open "SELECT DISTINCT Region FROM Customers WHERE Country = '" & strCountry & "' ORDER BY Region",objConnection,3,3
            if objRS.eof then
                  Response.Write("<option>No Regions Found</option>")
            else
                  Response.Write("<option>Select Region Now</option>" & VBCRLF )
                  do while not objRS.EOF
                        if objRS("Region") = strRegion then
                              strSelected = " Selected "
                        else
                              strSelected = ""
                        end if
                        Response.Write("<option" & strSelected & ">" & objRS("Region") & "</option>" & VBCRLF )
                        objRS.MoveNext
                  loop
            end if
            objRS.Close
            set objRS=Nothing
      else
            Response.Write("<option>Select a Country First</option>")
      end if
end sub

sub makeCity()
      if strRegion <> "Select a Country First" AND  strRegion <> "Select Region Now" AND strRegion <>"" then
            if not isObject("objRS") then
                  set objRS=Server.CreateObject("ADODB.RecordSet")
            end if
            if objRS.state <> 0 then
                  objRS.close
            end if
            objRS.Open "SELECT DISTINCT City FROM Customers WHERE Region = '" & strRegion & "' ORDER BY City",objConnection,3,3
            if objRS.eof then
                  Response.Write("<option>No Cities Found</option>")
            else
                  Response.Write("<option>Select City Now</option>" & VBCRLF )
                  do while not objRS.EOF
                        if objRS("City") = strCity then
                              strSelected = " Selected "
                        else
                              strSelected = ""
                        end if
                        Response.Write("<option" & strSelected & ">" & objRS("City") & "</option>" & VBCRLF )
                        objRS.MoveNext
                  loop
            end if
            objRS.Close
            set objRS=Nothing
      else
            Response.Write("<option>Select a Region First</option>")
      end if
end sub
%>

<SCRIPT LANGUAGE=javascript>
<!--

function submitCountry(){
      var objForm = document.forms[0];
      objForm.elements['Region'].selectedIndex=0;
      objForm.elements['City'].selectedIndex = 0;
      objForm.submit();
}
function submitRegion(){
      var objForm = document.forms[0];
      objForm.elements['City'].selectedIndex = 0;
      objForm.submit();
}

//-->
</SCRIPT>

</HEAD>
<BODY>
<FORM action="MultiSelect.asp" method=POST id=form1 name=form1>
<SELECT  name="Country" onChange="submitCountry()">
      <%call  makeCountry%>
</SELECT><br>
<SELECT  name="Region" onChange="submitRegion()">
      <%call makeRegion%>
</SELECT><br>
<SELECT  name="City">
      <%call makeCity%>
</SELECT><br>

<p><INPUT type="submit" value="Submit" id=submit1 name=submit1></p>
</FORM>
</BODY>
<%
objConnection.Close
set objConnection = Nothing
%>

</HTML>


As for submitting the data once the form was complete, I would recommend, as has already been discussed above, just changing the action of the form via javascript.

Fritz the Blank
0
fritz_the_blankCommented:
This is how I dealt with the final submission:

function submitForm(){
      var objForm = document.forms[0];
      objForm.action = "http://www.FairfieldConsulting.com/processform.asp"
      return true;
}


Then on your form tag, do this:

<FORM action="" method=POST id=form1 name=form1 onSubmit="return submitForm()">


FtB
0
Chris_GrangerAuthor Commented:
Thanks fritz, yes i modified some of that Northwind example to get the dropdown lists operating, added a request.form statement to populate an array to keep the form fields state when subbmitting to itself and added the following for the two types of submit it uses:

function submitForm(bType)
{
if (bType){
document.form1.action='myself.asp'}
else{
document.form1.action='nextpage.asp'}
document.form1.submit()
}

I guess adding the 'return' to the function is good practice?

cheers.
0
fritz_the_blankCommented:
If you call it from the form tag with the onSubmit method, adding a return true or return false is the best way to get predictable results.

The way that I had it origianally should have maintained state. Did that not work for you?


--FtB
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.