首页 > 解决方案 > Save button not responding- why DOM is null after I fill out data on UI

问题描述

Now I have a save button that's not working. When I click on it nothing happens on UI.

<img src="/something/image/Save.jpg" border="0" style="cursor:hand" alt="Save" 
onclick="if(validate_edit()){pop_comment('edit');}"> 


function pop_comment(src)
{
 //document.all.comment.value=document.getElementsByTagName('comment');
 window.showModalDialog("./jsp/util/comment.jsp?src="+src, window, "dialogHeight=320px; dialogWidth=500px; dialogLeft=100px; dialogTop=150px; resizable=yes; status=no;scroll=no;");
}

After I click on Save button I see below error on console:

violator_edit.do:354 Uncaught TypeError: Cannot read property 'value' of null
    at validate_edit (edit.do:354)
    at HTMLImageElement.onclick (edit.do:1035)

and says this line in validate_edit() caused the error:

var state = document.getElementById('wsbean.state').value;

I wrote this test:

if(document.getElementById('wsbean.state')==null)(console.log("null"))

Result: 
null

So the DOM object is not ready. But why? I did fill out state on UI. Could it be because of the script tag position? the HTML of the page looks like this:

<html>
  <head></head>
  <body>
    <Script></Script>
    <div></div>--> the whole form is inside this div
  </body>
</html>

标签: javascripthtmldom

解决方案


推荐阅读