Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
Problem with Ajax and Classic ASP Request.Form

 
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help
View previous topic :: View next topic  
Author Message
tenderfoot
New one
New one


Joined: 08 May 2008
Posts: 2

PostPosted: Thu May 08, 2008 2:10 pm    Post subject: Problem with Ajax and Classic ASP Request.Form Reply with quote

Hiya

I have a problem with some Ajax functionality and I was wondering if someone could help a noob?

I created a form with two select boxes that are dynamically populated. That is, the second is populated according to the selection of the first.

The code is like so:
Code:

<form method="post" action="index.asp" id="storeLocator" name="storeLocator">

   <label for="region">Select your country</label>
   <select name="country" id="country" onchange="selectTown(this.value);">
      <option value="1">England</option>   
      <option value="2">Ireland</option>   
      <option value="3">Scotland</option>   
      <option value="4">Wales</option>   
   </select><br />
   
   <label for="town">Select your region</label>
   <div id="county">
      <select name="county">
         <option value="0" selected="selected">Choose region</option>
      </select>
   </div>

   <input type="submit" name="submit" id="submit" value="Submit"  />
</form>


When you select a country from the first select box, it runs this javascript

Code:

<script type="text/javascript">
      var xmlHttp   

      //this function is envoked when the user makes a selection from the first select box   
      function selectTown(str)
      {
         xmlHttp=GetXmlHttpObject();
         if (xmlHttp==null)
              {
              alert ("Your browser does not support AJAX!");
              return;
              }
               //The variable CountryID is passed to the script store-locator-index.asp which executes a query to get the counties for that store.
               var url="/includes/store-locator-index.asp";
               url=url+"?CountryID="+str;
               xmlHttp.onreadystatechange=stateChanged;
               xmlHttp.open("GET",url,true);
               xmlHttp.send(null);
               
               

      }


      //When state changes has run, output the results to the markup id'ed as 'country'
      function stateChanged()
      { if (xmlHttp.readyState==4)
         //If a response exists, insert the results into the HTML element with the ID 'county'. 'county' replaces the second select box in the HTML example above
         { document.getElementById("county").innerHTML=xmlHttp.responseText;}
      }

      //Create xmlhttpObject
      function GetXmlHttpObject()
      { var xmlHttp=null;
         try
           {
           // Firefox, Opera 8.0+, Safari
           xmlHttp=new XMLHttpRequest();
           }
         catch (e)
           {
           // Internet Explorer
           try
            {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
           catch (e)
            {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
           }
         return xmlHttp;
      }




      </script>


This is the SQL and ASP executed in the file store-locator-index.asp. The output is inserted into the div with the ID 'county' in the form illustrated above.
Code:

<%    


   If isNumeric(Request.QueryString("CountryID")) Then
         Dim SQL9         
         SQL9 = "SELECT * FROM CountyRegions WHERE regionID  ='" & cint(Request.QueryString("CountryID")) & "' ORDER BY countyName ASC;"
         ' Create and open ADO recordset
         Set rsCounties = Server.CreateObject("ADODB.Recordset")
         rsCounties.CursorType = 3
         rsCounties.CursorLocation = 3
         rsCounties.LockType = 1
         rsCounties.Open SQL9, db


         If NOT rsCounties.EOF Then
         selected = 1

            Response.Write("<select>")
               Do while NOT rsCounties.EOF
                  If selected = 1 Then   
                     Response.Write("<option value=" & rsCounties.Fields.Item("countyID") & " selected=""selected"">" & rsCounties.Fields.Item("countyName") & "</option>")
                  Else
                     Response.Write("<option value=" & rsCounties.Fields.Item("countyID") & ">" & rsCounties.Fields.Item("countyName") & "</option>")
                  End If
                  selected = 0
               rsCounties.MoveNext()
               Loop   
            Response.Write("</select>")
         Else
            Response.Write("<select><option>Currently No Regions</option></select>")
         End If
   Else
         Response.Write("<select><option>Please select a Country</option></select>")
   End If

%>



With a country selected, and the county list populated, the user selects a county and clicks the submit button:

Code:

'If the submit button for the store locator is clicked   
 If Request.Form("submit") <> "" Then
 
   CountyID = Request.Form("county")
   CountryID = Request.Form("country")

   Response.Redirect(Domain & "stores.asp?CountyID=" & CountyID & "&CountryID=" & CountryID & "")
Else
End If


The problem is, is that Request.Form("county") does not work. This is because the HTML is inserted dynamically into the div with the ID 'county'.
If I place a hidden variable inside and outside the county div, Request.Form only works for the hidden variable outside the div with the ID 'county'.

Is there a way to get this value to post so i can grab it with Request.Form?


Thanks in advance!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 Advertisements
 XML & Copyright Notice 
    


Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X


Link to our site:

  


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos


Normal Bookmark


Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax


Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?


Credits:
it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert