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
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


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:

<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>

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

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


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

      //this function is envoked when the user makes a selection from the first select box   
      function selectTown(str)
         if (xmlHttp==null)
              alert ("Your browser does not support AJAX!");
               //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";


      //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;
           // Firefox, Opera 8.0+, Safari
           xmlHttp=new XMLHttpRequest();
         catch (e)
           // Internet Explorer
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
           catch (e)
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
         return xmlHttp;


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.


   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

               Do while NOT rsCounties.EOF
                  If selected = 1 Then   
                     Response.Write("<option value=" & rsCounties.Fields.Item("countyID") & " selected=""selected"">" & rsCounties.Fields.Item("countyName") & "</option>")
                     Response.Write("<option value=" & rsCounties.Fields.Item("countyID") & ">" & rsCounties.Fields.Item("countyName") & "</option>")
                  End If
                  selected = 0
            Response.Write("<select><option>Currently No Regions</option></select>")
         End If
         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:


'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 & "")
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
 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 ?

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