3 Replies Latest reply: Nov 7, 2011 4:33 PM by DrClap RSS

    Get the value of an element

    801863
      Hi everybody,
      I have the following two objects in a JavaScript function:
      var title = document.createElement("div");
      title.id="titleDiv_" + creativeList[0].id;
      title.style.marginTop="15px";     
                     
      var left = document.createElement("div");
      left.id="left";               
      left.innerHTML = "<input readonly id=\"left1\" type=\"text\" name=\"inputLeft\" size=3 maxlength=3 value=\"35\"><font>characters left</font>";
      
      title.innerHTML = "TITLE:  &nbsp <input maxlength=\"" + <c:out value="${titleMaxSize}"/> + "\" size=\"" + <c:out value="${titleMaxSize}"/> + "\" type=\"text\"  id=\"title_" + creativeList[0].id + "\" name=\"inputTitle\" value=\"" + creativeList[0].title + "\">";
      On the website, I see the fields with the "values" as follows; meaning it does show the values:

      TITLE: Auto Body and Paint --> "Auto Body and Paint": is the value
      35 characters left --> "35" is the value

      I try to get the values as following:
      if(document.getElementById("title_" + creativeList[0].id).value.length == 0) {
                        alert("Title: nothing");
                    }else{
                         alert("Title: found: " + ("title_" + creativeList[0].id).value);
                    }
      
                if(document.getElementById('left1').value.length == 0) {
                        alert("Left: nothing");
                    }else{
                         alert("Left: found: " + ('left1').value);
                    }
      I don't receive any error, however, this is what I get:

      Title: found: undefined
      Left: found: undefined
                
      How can I get the real values? Any help is gretly apprecaited.