html - FindElementByID referencing Null (called from Javascript) -


i have javascript code written in iframe, modifying value of hiddenfield in contentplaceholder in parent window, , firing click event of button, , setting visibility of iframe. referenced erroneously.

javascript in iframe:

 <script type="text/javascript">       function changeview(obj) {            parent.document.getelementbyid("hiddenfield1").value = $(obj).attr('id');           parent.document.getelementbyid("button1").click();           var iframe = parent.document.getelementbyid("newsframe");           iframe.style.display = "block";        }      </script> </head> <body>    <form id="f">     <nav>       <ul id="nav">         <li><a id="ahome"  href="#" onclick="changeview(this)" >home</a></li>            <li><a href="#">about</a>           <ul>             <li><a id="amessage" href="#" onclick="changeview(this)">message</a></li>            </ul>         </li>       </ul>     </nav>  </form> </body> 

parent page:

<asp:content id="content3"  contentplaceholderid="contentplaceholder2" runat="server">    <html xmlns="http://www.w3.org/1999/xhtml" >   <head>     <title> </title> <script runat="server">      sub changeview()         dim t hiddenfield         ' dim mc control = findcontrol("label1")         t = findcontrol("hiddenfield1")         dim m multiview         m = findcontrol("multiview1")          if (t.value = "ahome")             m.activeviewindex = 0          end if         if (t.value = "amessage")             m.activeviewindex = 1         end if      end sub     </script>  </head>  <body>    <form id="form1" runat="server">     <asp:button id="button1" runat="server"  visible="true" onclick="changeview"  />         <asp:scriptmanager id="sm1" runat="server" />  <asp:updatepanel id="updatepanel1" runat="server">         <contenttemplate>         <asp:hiddenfield id="hiddenfield2"  runat="server"  />          <asp:multiview id="multiview2" runat="server" activeviewindex="0">             <asp:view id="view8" runat="server">                 home              </asp:view>             <asp:view id="view9" runat="server">                 department message              </asp:view>          </asp:multiview>         <br /><br />           </contenttemplate>     </asp:updatepanel>    </form>  </body> </html>                 <iframe src="dept-menu/index.html" width="100%" height="650px" scrolling="no" frameborder="0"></iframe>                      <iframe id="newsframe" src="dept-news/news.html" width="100%" height="300px" scrolling="no" frameborder="0"></iframe>    </asp:content> 

html

 <input type="submit" name="ctl00$contentplaceholder2$button1" value="" id="button1" />          <script type="text/javascript"> //<![cdata[ sys.webforms.pagerequestmanager._initialize('ctl00$contentplaceholder2$sm1', 'form1', ['tctl00$contentplaceholder2$updatepanel1','contentplaceholder2_updatepanel1'], [], [], 90, 'ctl00'); //]]> </script>    <div id="contentplaceholder2_updatepanel1">          <input type="hidden" name="ctl00$contentplaceholder2$hiddenfield1" id="hiddenfield1" />                  home           <br /><br />    </div> 

at runtime error says can't set value of null reference. doing wrong? in advance.

p.s. iframe called contentplaceholder.

simply added

      parent.document.getelementbyid("contentplaceholder2_hiddenfield1").value = $(obj).attr('id'); 

instead of

      parent.document.getelementbyid("hiddenfield1").value = $(obj).attr('id'); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -