Solved

Jquery in an attribute?

Posted on 2011-09-16
4
173 Views
Last Modified: 2012-06-27
Why doesnt this work?

txtTimeBox1.Attributes.Add("onload", "$('" + txtTimeBox1.ID + "').text('Hi')");

I dont necessarily need for the textbox to say hi.  What Im trying to do is add jquery dynamically to a server control

Thanks Experts!
0
Comment
Question by:jdn717
  • 2
4 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 36547742
try this

txtTimeBox1.onload = function(){
  this.val( "Hi" );
};

But i don't think that a input box can have onload event, so also try

document.ready(function(){
   $("textbox1Id").val("Hi");
});

also you can simple have the value in the textbox
<input type="text" value="Hi">
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36548005
When using ID selector you need # for selector
 
Try this

txtTimeBox1.Attributes.Add("onload", "$('#" + txtTimeBox1.ID + "').text('Hi')");
0
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 499 total points
ID: 36548018
OR

txtTimeBox1.Attributes.Add("onload", "$('#" + txtTimeBox1.ClientID + "').text('Hi')");
0
 

Author Closing Comment

by:jdn717
ID: 36562013
The answer was correct, not necessrly what i was lookng for.  Mainly because of my failure to describe it better
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now