dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Can't pass Variable to getElementByID

  1. #1
    Join Date
    Feb 2007
    Posts
    3

    Exclamation Can't pass Variable to getElementByID

    Hi,

    I am trying to pass a variable into where I would getElementByID and it always says "document.getElementById(prodColorName) has no properties. I think I have tried everything. The problem seems to be occuring in function colorStateChanged in this line "document.getElementById(prodColorName).innerHTML = xmlHttp.responseText;
    "
    Here is the full code:

    function sizeGetColor(selectedSize,currentColor,prodID,setNumber)
    {
    var url="http://estrategize.mailwebsol.com/Yandy/setOptionAjax.php?prodID=" + prodID + "&size=" + selectedSize + "&action=sizeGetColor&currentColor=" + currentColor + "&setNumber=" + setNumber;
    number=setNumber
    xmlHttp=GetXmlHttpObject(colorStateChanged)
    xmlHttp.open("GET", url , true)
    xmlHttp.send(null)
    }

    function colorStateChanged()
    {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
    var prodColorName="prodColor"+number;
    document.getElementById(prodColorName).innerHTML = xmlHttp.responseText;
    }
    }

    function GetXmlHttpObject(handler)
    {
    var objXmlHttp=null

    if (navigator.userAgent.indexOf("Safari")>=0)
    {
    objXmlHttp=new XMLHttpRequest()
    objXmlHttp.onload=handler
    objXmlHttp.onerror=handler
    return objXmlHttp
    }
    if (navigator.userAgent.indexOf("Opera")>=0)
    {
    objXmlHttp=new XMLHttpRequest()
    objXmlHttp.onload=handler
    objXmlHttp.onerror=handler
    return objXmlHttp
    }
    if (navigator.userAgent.indexOf("MSIE")>=0)
    {
    var strName="Msxml2.XMLHTTP"
    if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
    {
    strName="Microsoft.XMLHTTP"
    }
    try
    {
    objXmlHttp=new ActiveXObject(strName)
    objXmlHttp.onreadystatechange=handler
    return objXmlHttp
    }
    catch(e)
    {
    alert("Error. Scripting for ActiveX might be disabled")
    return
    }
    }

    if (navigator.userAgent.indexOf("Mozilla")>=0)
    {
    objXmlHttp=new XMLHttpRequest()
    objXmlHttp.onload=handler
    objXmlHttp.onerror=handler
    return objXmlHttp
    }
    }

  2. #2
    Join Date
    Mar 2006
    Posts
    100
    Do you have the tag info for prodColorName?

  3. #3
    Join Date
    Aug 2008
    Posts
    1

    Passing variables to getElementById method

    Hi,

    you can pass the variable appending a empty string to it:
    something like this:
    getElementById(varName+'')

    This works for me.

    --
    Dadasaheb Honde

Similar Threads

  1. Replies: 5
    Last Post: 04-17-2008, 01:29 PM
  2. Replies: 3
    Last Post: 10-13-2005, 11:14 AM
  3. Replies: 37
    Last Post: 10-30-2002, 06:21 AM
  4. Re: how to pass variable to a timer event?
    By Jason Sobell \(iGadget\) in forum .NET
    Replies: 0
    Last Post: 10-26-2002, 09:05 AM
  5. Pass asp variable to javascript
    By suresh in forum ASP.NET
    Replies: 9
    Last Post: 06-16-2000, 04:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center