Click here to Skip to main content
15,905,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

When I click li (line) then open new windoes form new tab.

Eample :
<li id ="mcsreport"> <a href="#"> Report </a>  </li>


C#
$(document).ready(function () {
            $('#mcsreport').click(function () {

                if ($('#txtSessionValue').text.toString() == 0) {
                    window.open("../../Security/FRM/FrmLogin.aspx", "_self");

                }
                else {
                    window.open("../../Report/FrmReportMdiMain.aspx", "_self");
                    
                }
            });
        });


this code is not work properly. please help...
Posted
Comments
G4mm4R4y 31-Jul-13 13:54pm    
Many things have not been said, im no javascript wiz but some problems may be in the html also. A few questions: External script or internal. What is the id of the javascript area EX: <script id="ID">YOURSCRIPT</script> If the id is something other than id="" Than it wont work. if it is id="ID" than the above would have to be href="#ID".

Try using the following piece of code.


JavaScript
<li id="mcsreport">
    <a href="../../Security/FRM/FrmLogin.aspx" target="_self">Report</a>
</li>

$(document).ready(function () {
     $('#mcsreport').click(function () {
         if ($('#txtSessionValue').text.toString() == 0) {
             $(this).find('a').attr('href', "../../Security/FRM/FrmLogin.aspx").click();
         }
         else {
             $(this).find('a').attr('href', "../../Report/FrmReportMdiMain.aspx").click();
         }
         return false;
     });
});
 
Share this answer
 
Try the following code:

<li id="mcsreport"> <a href="#"> Report </a>  </li>


C#
$(document).ready(function () {
     $('#mcsreport').click(function () {
        var w = window.open('about:blank', '_blank');
        if ($('#txtSessionValue').text.toString() == 0) {
            w.open("../../Security/FRM/FrmLogin.aspx", "_self");
        }
        else {
            w.open("../../Report/FrmReportMdiMain.aspx", "_self");                 
        }
     });
});


Hope this Helps You...
Happy Coding :)
 
Share this answer
 
v2
Your code needs a slight modification which I think is the issue -
JavaScript
$(document).ready(function () {
            $('#mcsreport').click(function () {

                if ($('#txtSessionValue').text.toString() == 0) {
                    window.open("../../Security/FRM/FrmLogin.aspx", "_self");

                }
                else {
                    window.open("../../Report/FrmReportMdiMain.aspx", "_self");

                }
            });
});


Inside if conditional expression -
$('#txtSessionValue').text.toString() == 0

text() should be a function but not a property. Because every jQuery object relates to an action. So, it should be -
if($('#txtSessionValue').text().toString() == 0)


Hope this will solve your problem.
Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900