Click here to Skip to main content
15,938,682 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have hidden field,anchor tag in aspx page i.e.


ASP.NET
<asp:HiddenField ID="HdnsmallImageAfter" runat="server" Value="" />

<a id="ahrefAfter" href="javascript:getvalue(HdnsmallImageAfter.Value);" runat="server" title="AFTER">ABC</a>


and want to call javascript function i.e.

JavaScript
function getvalue(value)
{
 if(value == "abc")
{
}
}


but its not working...
Posted
Updated 20-Feb-12 0:58am
v2

XML
<a id="ahrefAfter" href="javascript:getvalue( <%=HdnsmallImageAfter.ClientID%>.value);" runat="server" title="AFTER">ABC</a>
or 
<a id="ahrefAfter" href="javascript:getvalue( <%=HdnsmallImageAfter.ClientID%>);" runat="server" title="AFTER">ABC</a>

function getvalue(id)
{
var txt=document.getElementById(id);
 if(txt.value == "abc")
{
}
}
 
Share this answer
 
Comments
Punit Belani 20-Feb-12 7:10am    
i want exact what you have done in first part,but it gives me "syntax error" .

and

second part does not help me because this function called from many place with passing direct values so i cannot use it. because it passes id instead of value, right?
Hi, call JS function on textbox. use below code for this:

ASP.NET
<a id="ahrefAfter" href="javascript:void(0);" onclick="javascript:getvalue();" runat="server" title="AFTER">ABC</a>


JS Function

JavaScript
function getvalue()
{
hdnObj = document.getElementById('<%=HiddenField.ClientID%>');
alert(hdnObj.value);
}
 
Share this answer
 
This Is Working For ME:

ASP.NET
<asp:hiddenfield id="HdnsmallImageAfter" value="abc" runat="server" xmlns:asp="#unknown" />
<a id="ahrefAfter" href="javascript:getvalue(HdnsmallImageAfter.value);" runat="server" title="AFTER">ABC</a>


C#
function getvalue(v) {

       if (v == "abc") {
           alert("HI");
       }
   }
 
Share this answer
 
Hey,
i think proble occured because of Master page
if u used master page then use following code

C#
function getvalue(value) {
            
            alert(value);
        }


replace HdnsmallImageAfter.Value with ContentPlaceHolder1_HdnsmallImageAfter.Value

Note- replace ContentPlaceHolder1 with ur contenplaceholder id
 
Share this answer
 
v3
Hey thanks All,
finally from your hints i done with:

JavaScript
href="javascript:getvalue(document.getElementById('ctl00_ContentPlaceHolder1_HdnsmallImageAfter').value);"
 
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