acces an object in user control with javascript

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
3/12/2010 3:35:03 PM
Gravatar
Total Posts 76

acces an object in user control with javascript

Hello, i have made a custom module (guestbook).

In this custom module (*.ascx file) i have a textbox with id="txtMessage".

How can i acces this object with javascript. I now have this:

<script type="text/javaScript">
var dob = '<%= txtMessage.ClientID %>';
</script>

But i don't seem to manage to get acces to this control.

The only reason i can imagine is that there is some extra control/page/module between the custom-module and the main page.

In the sourcecode of the webpage i see "maincontent" standing before "txtmessage".

 

Please help!

3/13/2010 10:22:19 AM
Gravatar
Total Posts 18439

Re: acces an object in user control with javascript

Hi Hanzie,

The ClientID is just the id string that the control will render it does not give a reference to the control itself, to get the value of the TextBox you would do it like this:

var dob = document.getElementById( '<%= txtMessage.ClientID %>').value;

or more clean using jQuery

var dob = $('#<%= txtMessage.ClientID %>').val();

Hope it helps,

Joe

3/13/2010 11:30:13 AM
Gravatar
Total Posts 76

Re: acces an object in user control with javascript

Hello Joe,

Thnx for youre reply. So you mean I wasn't refering/accesing the textbox, I only declared the clientid from the textbox to the variable dob.

I needed a way to put a smiley on the textbox. I managed now with this line:

var dob = document.getElementById('<%= txtMessage.ClientID %>'); //acces the textbox

THNX AGAIN!

You must sign in to post in the forums. This thread is closed to new posts.