0

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.

1
  • In document.getElementByID("GridViewname"), GridViewName shouldn't be in quotes Commented Mar 26, 2013 at 11:53

4 Answers 4

3

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)
Sign up to request clarification or add additional context in comments.

Comments

0

You have a typo there, onClicke. This is wrong, should be onClick.

Comments

0

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');

}

1 Comment

I have more than one grid view in same page (I use the AJAX TabContainer)
-1

this works perfectly for inline code

OnClientClick='<%#String.Format("buttonstatus(""{0}"",""{1}"",""{2}"",""{3}"");return false;", Eval("listingid"), "D", "Archived", Eval("EndDate"))%>'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.