Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-10-2007, 07:44 PM   PM User | #1
Darth Sensei
New Coder

 
Join Date: Mar 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Darth Sensei is an unknown quantity at this point
I need help finding the stupid error with my code.

The code should be simple. When a user changes the "color" select control on my page, I use Ajax to generate a textbox if they choose "CM" as a color. The control goes into a div with id=LECCm. Here is the basic code:

From the main page:
Code:
<select name="LECColor" id="LECColor" onChange="checkLECCm()">
// this is followed by a ton of colors.

Here is the function:

Code:
function checkLECCm()
{
dataSource = '/DivTexts/LECCm.php?CM=' +document.signbuilder.LECColor.options[document.signbuilder.LECColor.selectedIndex].value;
alert(dataSource);
getData(dataSource, 'LECCm');
}
Which calls the function:
Code:
function getData(dataSource, divID) 
{
alert(dataSource);
	ajaxSetup();
	  if (xmlHttp) {
		var obj = document.getElementById(divID);
		xmlHttp.open("GET", dataSource);
		
		xmlHttp.onreadystatechange = function()
		{
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				obj.innerHTML = xmlHttp.responseText;
			}
	  }
  }
   xmlHttp.send(null);
  }
Which calls the function (last one, promise):
Code:
function ajaxSetup() {
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
}
The code to determine if the CM box should be shown is the php file:
PHP Code:
<?php
if ($_GET["CM"]=="CM") {

$displayCM '<label>CM=</label><input name="LECCm" type="text" id="LECCm" size="12" maxlength="12" />';
    } else {
    
$displayCM ""
}
echo 
$displayCM;
?>
Here is the problem. When I choose another color everything is fine. When I choose CM the proper control comes in correctly also. However, if the user switches to a different color the program does not remove the control. It just doesn't seem to work at all after CM is chosen.

Can any of you gurus figure out my problem? I've been over this code at least 30 times and have no idea what I did wrong.

Dave
Darth Sensei is offline   Reply With Quote
Old 04-10-2007, 09:28 PM   PM User | #2
Darth Sensei
New Coder

 
Join Date: Mar 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Darth Sensei is an unknown quantity at this point
Ok, this just defies reason, unless I"m missing something stupid. When I created another set of controls and div's and simply replaced the first L with a R it works on the second set, but not the first set. They call the exact same functions and php page as well.

Code:
        <select name="RECColor" id="RECColor" onChange="checkRECCm()">
Code:
function checkRECCm()
{
dataSource = '/DivTexts/LECCm.php?CM=' +document.signbuilder.RECColor.options[document.signbuilder.RECColor.selectedIndex].value;
alert(dataSource);
getData(dataSource, 'RECCm');	
}
What the heck is the difference?
Darth Sensei is offline   Reply With Quote
Old 04-10-2007, 09:44 PM   PM User | #3
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
Code:
getData(dataSource, 'LECCm');
LECCm is the div id where the textbox will be inserted, right?
But the textbox you are trying to insert inside the div has the same id as the div!
Code:
$displayCM = '<label>CM=</label><input name="LECCm" type="text" id="LECCm" size="12" maxlength="12" />';
Id should be unique otherwise document.getElementById won't work.
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 04-10-2007, 10:12 PM   PM User | #4
Darth Sensei
New Coder

 
Join Date: Mar 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Darth Sensei is an unknown quantity at this point
I can't thank you enough for your help. It was driving me mad.
Darth Sensei is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 07:58 AM.


Advertisement
Log in to turn off these ads.