Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > HTML, XML, Javascript, AJAX

Reply
 
LinkBack Thread Tools Display Modes
Old 04-01-2009, 07:23 PM   #1 (permalink)
AthleteTO
Recruit
 
Join Date: Apr 2009
Posts: 2
AthleteTO is on a distinguished road
Strange Behaviour in IE7 - Javascript only refreshes dropdown once

Strange little issue. Using Javascript and AJAX to pull in a drop down box for car models when a car make is chosen. Here's what happens: if I choose Ford, the Ford models appear. I choose Honda, the Honda models appear. But if I choose Ford again - the update doesn't happen. Essentially, anything that's already been selected will not reappear.

Here are the code snippets:

Code:
<script type="text/javascript">
function init(Make) {
	httpObject = getHTTPObject();
	if (httpObject != null) {
		httpObject.open("GET", "modeldropdown.asp?Type=<%=Request("Type")%>&Make="+Make.value, true);
		httpObject.send(null);
		httpObject.onreadystatechange = display;
	}
}

function display() {
	if(httpObject.readyState == 4){
		document.getElementById('model').innerHTML = httpObject.responseText;
	}
}

function getHTTPObject(){
	if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
		else if (window.XMLHttpRequest) return new XMLHttpRequest();
		else {
			alert("Your browser does not support AJAX.");
		return null;
	}
}

var httpObject = null;
</script>

                    <select name="Make" onChange="javascript:init(this)">
                      <option value="">&gt;&gt; Make</option>
                      <option value="Acura">Acura</option>
                      <option value="Audi">Audi</option>
                      <option value="BMW">BMW</option>
... etc...                       
                    </select>

                    <div id="model"><font size="1">Select a Make..</font></div>
Code:
<%
	If Request("Make") & "!" = "!" Then
%>
<font size="1">Select a Make..</font>
<%
	Else
	
%>
                    <select name="Model">
                      <option value="">&gt;&gt; Model</option>
                      <option value="">---------------</option>
                      <option value="Undecided">Undecided</option>
<%
		If Request("Type") = "New" Then
		
			sql = "Select * From New Where Make = '" & Request("Make") & "';"
			
		Else
		
			sql = "Select * From Used Where Make = '" & Request("Make") & "';"
			
		End If
		
		rs.open sql, conn
	 
		Do Until rs.EOF
%>
                      <option value="<%=rs("Model")%>"><%=rs("Model")%></option>
<%
			rs.movenext
			
		Loop
		
		rs.close
%>
                    </select>
<%
	End If
%>
Your thoughts on why this is happening are most appreciated!

Cheers..
Drew
AthleteTO is offline   Reply With Quote
Old 04-09-2009, 06:34 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
are you using firefox with firebug? my guess is that something to do with the honda selection is causing an js error and killing your script.
__________________
Mike
sde is offline   Reply With Quote
Old 04-10-2009, 03:30 PM   #3 (permalink)
AthleteTO
Recruit
 
Join Date: Apr 2009
Posts: 2
AthleteTO is on a distinguished road
It actually generates no javascript errors, and works correctly in Firefox (but not in IE7).

To be more clear - it doesn't matter which Make is chosen: once selected, it does not work if selected again. Only different Makes that have not already been selected will properly update the list.

Strange eh?

Drew
AthleteTO is offline   Reply With Quote
Old 04-10-2009, 03:46 PM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,706
sde is on a distinguished road
It may be related to your ajax request setup. I always recommend using a JS library like jquery for this.

Here's how the code may look to achieve what you're going for (not tested)
HTML Code:
<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript">
// do this when the document is loaded
$(document).ready(function(){
  
  // bind this change function to the #Make select
  $('#Make').change(function(){
    
    // use ajax to get the data
    $.get("modeldropdown.asp", { Type: "<%=Request("Type")%>", Make: $('#Make').val() },
      function(data){
        // place data in  #model
        $('#model').html(data);
      });
  });
});
</script> <select id="Make" name="Make"> <option value="">&gt;&gt; Make</option> <option value="Acura">Acura</option> <option value="Audi">Audi</option> <option value="BMW">BMW</option> </select> <div id="model"><font size="1">Select a Make..</font></div>
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
link behaviour gd0g HTML, XML, Javascript, AJAX 1 06-26-2008 07:50 AM
My CSS is doing strange things (not a bug) DavH27 HTML, XML, Javascript, AJAX 2 11-29-2006 04:26 AM
Odd behaviour after upgrade redhead Feedback 1 02-17-2006 02:18 PM
Windows' Strange Behaviour! plonkeroo Windows 12 07-16-2004 08:05 PM
Strange Problem Ilya020 HTML, XML, Javascript, AJAX 4 12-09-2003 03:05 PM


All times are GMT -8. The time now is 06:07 PM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting