can't update div

Discussion in 'JavaScript' started by aras, May 28, 2007.

  1. #1
    Hello

    We have a set of <div>'s and <span>'s chained inside like

    <div id="x">

    <span class="y"></span>
    <span class="something"></span>

    <div id="xx">...something..... there is a java onhandler function here draw();</div>
    <div id="yy"></div>

    Now the problem is the onhandler function is supposed to access document.getelementbyid("yy") but i got a java error stating not found element.

    How can i make this access there?
     
    aras, May 28, 2007 IP
  2. bosko

    bosko Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Not Java, but JavaScript. And not getelementbyid but getElementById. Maybe your problem is in this syntax error.... If not, post more code (java script also).
     
    bosko, May 28, 2007 IP
  3. aras

    aras Active Member

    Messages:
    533
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    60
    #3
    HTML
    
    <span class="label">Back Links:</span><input type="radio" name="linktype" id="linktype" value="2" onClick="toggler('backlinks')"  /><br /><br />
    <div id="backlinks" style="display: none;"><span class="label">How Many Backlinks</span><select name="bl" onChange="drawforms()"><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option></div><br /><br />
    <div id="backforms"></div>
    
    Code (markup):

    JS here.
    I did not include all operations, they are not needed. I have tried different combinations and the error is in the div updating part below.
    
    function drawforms() {
    
    // some operations here
    document.getElementById("backforms").innerHTML = str;
    
    }
    
    Code (markup):
     
    aras, May 28, 2007 IP
  4. bosko

    bosko Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You are missing closing </select> tag.
    From your code it seems that depending on dropdown selection you want to display different content in <div id="backforms">? Here is a function that check which value was selected and then update a div (now it's working only with number 0 as an example):

    function drawforms() {
    	var loc = document.getElementById("backforms");
    	var x = document.getElementById("b1"); 
    	var y = x.options[x.selectedIndex].text;
    	if(y == 0) { loc.innerHTML = 'Here I am!';}
    	}
    Code (markup):
    You have to add to <select> an id="b1". Also add as a _first option_ an empty string or something like "Make selection". Why? You're using onchange and when page loads number 0 will be already selected. So when you try to select 0 nothing will happen.
     
    bosko, May 28, 2007 IP