You must Sign In to post a response.
  • Category: JavaScript

    Document.getElementById (Urgent)

    Hi all ,
    Below javascript code is working fine in IE but not in Firefox and Chrome, Any Idea?

    function Openreport() {
    var report;
    var year = document.getElementById('Contentplaceholder2_txtYear').value; ;
    var month = document.getElementById('Contentplaceholder2_ddlMonth').value;
    var status = document.getElementById('Contentplaceholder2_ddlLoanStatus').value;
    report = window.open("LoanDetailsReport.aspx?year=" + year + "&month=" + month + "&status=" + status, "report", "width=200,height=100");

    }
  • #765950
    Are you getting any error message?
    What output you are getting?
    Are you using server side controls / Client side controls?

    The problem may be in the id of the control.

    var year = document.getElementById('Contentplaceholder2_txtYear').value; ;

    If you are using server side control and trying to get <%=ControlName.ClientId%> , you may get the the issue to get the id. Some times controls may populate with "$" inspite of "_"
    Try to see the page source, whether the id formed correctly.

    By Nathan
    Direction is important than speed

  • #765954
    try to put alert in javascript and see which line is return null; and see which line cause you error cause as per the expectation the code looks ok.
    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #765983
    Hi,

    Execute the same code in browser and debug the code and check what type of error you are getting and then send back those details with us, so that we can help you better.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #765998
    Hi,
    You are using document.getElementById('Contentplaceholder2_txtYear') because your controls are inside a Master Page.
    You can try document.getElementById('<%=txtYear.ClientID%>'), but it works only when your Openreport() function is on same ASPX page where your 'txtYear' control exist. It will not work if that function exist in some seperate .js file.
    If you have placed this Openreport() function in some .js file then go through below URL where you will find the best alternative to deal with this.
    http://www.codeproject.com/Articles/22111/Master-Pages-and-JavaScript-document-getElementByI

  • #766030
    Hi,

    Put console.log() to trace the output in between.You will get clear idea of where it breaking.

  • #766049
    Hai Chaminda,
    Sometimes one browser doesn't show up the actual error but it executes correctly without any issues while the other browser show-up the error.
    So you need to find-out the issue using some client browser tools like firebug. Install the firebug and then run your website under this tool will give you the error in the console tab. There you can see which part of the code is not running correctly under this browser.
    Also check the syntax of your code. Try below rewritten code:

    function Openreport() {
    var year = document.getElementById('Contentplaceholder2_txtYear').value;
    var month = document.getElementById('Contentplaceholder2_ddlMonth').value;
    var status = document.getElementById('Contentplaceholder2_ddlLoanStatus').value;
    var report = window.open('LoanDetailsReport.aspx?year='" + year + "'&month='" + month + "'&status='" + status+"', "report", "width=200,height=100");
    }

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com


  • Sign In to post your comments