[RESOLVED] Get the clientId for a button in a javascript
I have a code looking like this
Code:
function a()
{
...
displayNextButton( checkBoxesArray );
...
}
function displayNextButton( checkBoxesArray )
{
for( i = 0; i < checkBoxesArray.length; i++ )
{
alert("inne i loopen");
elem = checkBoxesArray[i];
if( !elem.checked )
{
alert("inne i if checked och visible");
document.getElementById('bNextPage').disabled = true;
return;
}
else
document.getElementById('bNextPage').disabled = false;
}
}
....
<asp:Button ID="bNextPage" OnClick="bNextPage_OnClick" Text="Vidare" Runat="server" />
But it doesn't work because the buttoncontrol is a runat server control so the name isn't bNextPage. But maybe I can use the clientId istead? How can I get the clientId name of the button?
You will have to use the Code Behind file to render the JavaScript on the final Page. The advantage of using Code Behind is that you get access to all server side controls and you can use the ClientID of all the controls. You can use Page.RegisterClientScriptblock method to register the script. You put the script into a string and then use the above method to render the JavaScript on the final page.
Use [code]your code here[/code] tags when you post source code
Search here before you post your question, someone might have already asked it before. My Articles
I don't think that is the right way to do it. It is better to use the Code Behind for this purpose. have you taken a look at RegisterClientScriptBlock method.
Use [code]your code here[/code] tags when you post source code
Search here before you post your question, someone might have already asked it before. My Articles
Yeah but the problem is that the first script that starts the otherone (that i want to start at the top ) has to be at the bottom. And the array that the first script makes is the data i need for the second one.....dilemma?!
Yeah but the problem is that the first script that starts the otherone (that i want to start at the top ) has to be at the bottom. And the array that the first script makes is the data i need for the second one.....dilemma?!
You need to make it simple for me to understand. Or else you can wait for PeejAvery to help you out. He is our scripting Guru.
Use [code]your code here[/code] tags when you post source code
Search here before you post your question, someone might have already asked it before. My Articles
Or else you can wait for PeejAvery to help you out. He is our scripting Guru.
Haha. Thanks but I just help as much as I can. I don't think I am any bit of a guru.
Covering multiple posts...No, you can't have colons within IDs nor names. They are invalid characters. And the script should run after the control is rendered since the rendering happens server-side and the script is JavaScript which is a client-side script.
In your first post you mention name and ID, the ID will be the same as the server's output so getElementById() is sufficient for JavaScript. If you have to have the name, you can use getElementById().name to return that.
I would suggest using Firefox's Error Console to debug your scripting part of it. After that, post back with more results.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Bookmarks