Click here to Skip to main content
15,890,995 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,


i am having a hyperlink control and a button control like this:

XML
<asp:HyperLink ID="name" runat="server" NavigateUrl="" Text="Narr"></asp:HyperLink>
                               <asp:LinkButton ID="btnLogout" CausesValidation="false" runat="server" Text="Logout"
                                   OnClientClick="confirmDelete();" OnClick="btnLogout_Click"></asp:LinkButton>


How can i get the text of the hyperlink using javascript:
Posted

VB
now try im updating


XML
<script language="javascript" type ="text/javascript" >
           function confirmDelete() {
               var lang = document.getElementById('name').innerHTML
               if (lang == 'Narr') {
                   var x = confirm("Are you sure you want to Log Out?");
               } else {
                   var x = confirm('Basha');
               }

           }
    </script>
 
Share this answer
 
v2
Comments
inayat basha 9-Mar-12 8:14am    
Microsoft JScript runtime error: Object required
Bojjaiah 9-Mar-12 8:22am    
did you try?
inayat basha 9-Mar-12 8:28am    
yes
inayat basha 9-Mar-12 8:28am    
same error
Bojjaiah 9-Mar-12 8:37am    
can you post your entire code? we will see where the error
try this
var value=document.getElementById( 'name' ).innerHTML;
 
Share this answer
 
Comments
inayat basha 9-Mar-12 7:23am    
<script language="javascript" type ="text/javascript" >
function confirmDelete() {
var lang = document.getElementById('name').innerHTML
if (lang.Value == 'ram') {
var x = confirm("Are you sure you want to Log Out?");
} else {
var x = confirm('Basha');
}

}
</script>

This is my Js wt i am using, but no value of the hyperlink is comming
Bojjaiah 9-Mar-12 7:31am    
in if condition you are validating 'ram' but this name not a hyperlink text

hyperlink text is 'Narr' you need change

if(lang=='Narr')

<script language="javascript" type ="text/javascript" >
function confirmDelete() {
var lang = document.getElementById('name').innerHTML
if (lang == 'Narr') {
var x = confirm("Are you sure you want to Log Out?");
} else {
var x = confirm('Basha');
}

}
</script>
inayat basha 9-Mar-12 7:37am    
but first i am taking the value/text of the hyperlink, so it is not equal it should go to else part ryte, but i am getting the null value, it was throwing me the exception
Bojjaiah 9-Mar-12 8:06am    
now try im updating

becz already getting value in lang object

but we are again validating lang.value that's y trowing exception so now try once again.
inayat basha 9-Mar-12 8:11am    
send me the js plz, which u have updated
try using document.getElementById("href").innerHTML
 
Share this answer
 
Comments
inayat basha 9-Mar-12 7:10am    
i have tired it was getting the text as null

var lang = document.getElementById("name").innerHTML;

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