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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    121
    Thanks
    22
    Thanked 3 Times in 3 Posts

    need help using variable to get elementID

    Here is the code I have:
    Code:
    var xmlhttpInk;
    
    function addInkOpt(iside,ivalue)
    {
    xmlhttpInk=GetXmlHttpObject();
    if (xmlhttpInk==null)
    	{
    	alert ("Browser does not support HTTP Request");
    	return;
    	}
    var url="/scripts/addink.php";
    url=url+"?q="+iside+"&k="+ivalue;
    url=url+"&sid="+Math.random();
    xmlhttpInk.onreadystatechange=InkChange(iside,ivalue);
    xmlhttpInk.open("GET",url,true);
    xmlhttpInk.send(null);
    }
    
    function InkChange(s,v)
    {
    var inkdivID="ink"+s+v;
    if (xmlhttpInk.readyState==4)
    	{
             document.getElementById(inkdivID).innerHTML=xmlhttpInk.responseText;
    	}
    }
    PHP Code:
    <div id="ink1div">
                <h3>Inks Side 1</h3>
                <div id="ink11">
                    <p>Ink:
                      <select name="InkID11" class="dropMenu" id="InkID11" onchange="addInkOpt(1,2)">
                        <option value="NULL"></option>
                        <?php do {  ?>
                        <option value="<?php echo $row_inkList['InkID']?>"><?php echo $row_inkList['InkDesc']?></option>
                        <?php } while ($row_inkList mysql_fetch_assoc($inkList));
                          
    $rows mysql_num_rows($inkList);
                          if(
    $rows 0) {
                              
    mysql_data_seek($inkList0);
                              
    $row_inkList mysql_fetch_assoc($inkList);
                          } 
    ?>
                      </select>Desc:
                      <input name="Ink1Desc1" type="text" class="inkdesc" id="Ink1Desc1" maxlength="25" />
                    </p>
              </div>
              <div id="ink12"></div>
              <div id="ink13"></div>
              <div id="ink14"></div>
              <div id="ink15"></div>
              <div id="ink16"></div>
              <div id="ink17"></div>
            </div>
            <div id="ink2div">
                <h3>Inks Side 2</h3>
                <div id="ink21">
                  <p>Ink:
                    <select name="InkID21" class="dropMenu" id="InkID21" onchange="addInkOpt(2,2)>
                        <option value="NULL"></option>
                        <?php do {  ?>
                        <option value="<?php echo $row_inkList['InkID']?>"><?php echo $row_inkList['InkDesc']?></option>
                        <?php } while ($row_inkList mysql_fetch_assoc($inkList));
                          
    $rows mysql_num_rows($inkList);
                          if(
    $rows 0) {
                              
    mysql_data_seek($inkList0);
                              
    $row_inkList mysql_fetch_assoc($inkList);
                          } 
    ?>
                      </select>Desc:
                    <input name="Ink2Desc1" type="text" class="inkdesc" id="Ink2Desc1" maxlength="25" />
                  </p>
                  </div>
                  <div id="ink22"></div>
                  <div id="ink23"></div>
                  <div id="ink24"></div>
                  <div id="ink25"></div>
                  <div id="ink26"></div>
                  <div id="ink27"></div>
                </div>
    could someone please help me figure out what I'm doing wrong?
    I'll try again to find, the thing that was my mind...
    The only other sign, it says I've lost my mind.

  • #2
    Regular Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    169
    Thanks
    26
    Thanked 3 Times in 3 Posts
    Nevermind........

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    121
    Thanks
    22
    Thanked 3 Times in 3 Posts
    figured it out.
    I had to move the var outside both functions, and add an empty string in the getElementById()

    Here's the final code if anyone is interested.
    Code:
    var xmlhttpInk;
    var inkdivID;
    
    function addInkOpt(iside,ivalue)
    {
    xmlhttpInk=GetXmlHttpObject();
    if (xmlhttpInk==null)
    	{
    	alert ("Browser does not support HTTP Request");
    	return;
    	}
    var url="/scripts/addink.php";
    url=url+"?q="+iside+"&k="+ivalue;
    url=url+"&sid="+Math.random();
    inkdivID="ink"+iside+ivalue;
    xmlhttpInk.onreadystatechange=InkChange;
    xmlhttpInk.open("GET",url,true);
    xmlhttpInk.send(null);
    }
    
    function InkChange()
    {
    if (xmlhttpInk.readyState==4)
    	{
    	document.getElementById(inkdivID+"").innerHTML=xmlhttpInk.responseText;
    	}
    }
    I'll try again to find, the thing that was my mind...
    The only other sign, it says I've lost my mind.

  • #4
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    We did not know what was the problem at the first.

  • #5
    Regular Coder
    Join Date
    Jun 2009
    Posts
    121
    Thanks
    22
    Thanked 3 Times in 3 Posts
    sorry, I should have said specifically, it's not working. originally, when I changed the dropdown, it did nothing.
    I'll try again to find, the thing that was my mind...
    The only other sign, it says I've lost my mind.

  • #6
    Regular Coder
    Join Date
    Jun 2009
    Posts
    121
    Thanks
    22
    Thanked 3 Times in 3 Posts
    ok, new question.
    is there a way to do the same thing without having all the DIV tags in already? somehow get the javascript to generate the DIV tag and the info, or just add what's in the <p> tags to the same div?
    I'll try again to find, the thing that was my mind...
    The only other sign, it says I've lost my mind.

  • #7
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    try this:
    Code:
    var newDiv = document.createElement("div");
    newDiv.innerHTML = "<p>all your html code here</p>"; // this could be as well xmlhttpInk.responseText;
    
    var objToInserBefore = document.getElementById("someId");
    objToInserBefore.parentNode.insertBefore(newDiv,objToInserBefore);

  • Users who have thanked ckeyrouz for this post:

    Alith7 (07-30-2009)


  •  

    Posting Permissions

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