Reputation: 25
I want to pass a parameter to a JavaScript function to use in document.getElementByID() as follows:
function PrinGridView(GridViewname)
{
var TableRow= document.getElementByID("GridViewname").getElementsBytagName("tr");
var td= TableRow.item(0).getElementsBytagName("th");
if(td.length>0)
alert('done');
}
In my asp page, I have an image button event:
onClicke="PrinGridView("<%=MyGrideView.ClientID%>")";
but it does not work well.
How can I pass the GridView to a function?
Thanks.
Upvotes: 0
Views: 10806
Reputation: 1
this works perfectly for inline code
OnClientClick='<%#String.Format("buttonstatus(""{0}"",""{1}"",""{2}"",""{3}"");return false;", Eval("listingid"), "D", "Archived", Eval("EndDate"))%>'
Upvotes: -1
Reputation: 175748
Javascript is case sensitive; it's getElementById
not getElementByID
, getElementsByTagName
not getElementsBytagName
etc.
There are other typos; F12 in your browser and the Error/Console will display script errors.
You need to mix quotes as the below is not valid, aside from the typo its not a parseable string as the quotes are broken:
onClicke="PrinGridView("<%=MyGrideView.ClientID%>")";
Change to
onClick="PrinGridView('<%=MyGrideView.ClientID%>')";
Within the function you quote what should probably be the argument, change from
var TableRow = document.getElementByID("GridViewname")
to
var TableRow= document.getElementById(GridViewname)
Upvotes: 3
Reputation: 12176
Try like this
onClick="PrinGridView(this)"
function PrinGridView(obj)
{
var gridName = obj.id;
var TableRow= document.getElementByID(gridName).getElementsBytagName("tr");
var td= TableRow.item(0).getElementsBytagName("th");
if(td.length>0)
alert('done');
}
Upvotes: 0