Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Build a dynamic onclick behavior 1

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
US
I have an ajax driven form. After a selection is made and the form elements are populated I need to dynamically set the onclick behavior of a div. My approach (if there's an easier way I'm listening) is to set the div's innerHTML to the following:
Code:
document.getElementById('DMWinXfer').innerHTML='<span onclick="alert('my message')">Click Here</span>';
Of course that fails because of the quotes... I've been trying to construct the contents but keep getting errors. Usually "Expected )" or "Expected ;". Here is how I thought it would work:
Code:
document.getElementById('DMWinXfer').innerHTML='<span onclick=+'"'+'alert('+"'"+'my message+"'"+');'+'"'+'>Click Here</span>';

Thanks in advance

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
How about actually setting the div's onclick event instead of adding a span to click.
Code:
document.getElementById('DMWinXfer').onclick=function(){ alert('My Message')};



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Thanks Phil! I knew I was making that too hard.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top