Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    New Coder
    Join Date
    Mar 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,960
    Thanks
    0
    Thanked 236 Times in 233 Posts
    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.

  • #4
    New Coder
    Join Date
    Mar 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can't thank you enough for your help. It was driving me mad.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •