[quote=223632:@Eugene Dakin]I am trying to create a function and I must be missing something simple. An example of the program is here: Function Example
There are two buttons and the first button works when it opens an alert and says ‘Hello out there!’.
The second button calls a function which should call the same alert but with a function and doesn’t work. Here is the code:
[code] Me.MyHTML = Me.MyHTML + “
Change HTML with buttons
” +_ 'Header
"
" //Horizontal Rule
Me.MyHTML = Me.MyHTML +"<button onclick="“alert(‘Hello out there!’)”";>Press (works)
"
Me.MyHTML = Me.MyHTML +“Press (Doesn’t work)” +_
“”
Me.MyHTML = Me.MyHTML + “”[/code]
This code is in the Open event of the WebControlWrapper called MyHTMLArea1.
Any helpful thoughts?[/quote]
I usually do not use the concatenation technique. It is hard to read and doubling quotes is source of error. What I do is place the HTML or JavaScript into a constant. It is much easier to edit as well.
I picked the code at http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick to make sure it works, since I could not get what you posted to work in an HTML page.
Here is what I placed in a hello constant :
[code]
test
Direct alert
Click function
[/code]
I tried to keep the script in there but the function did not work. So I placed that in App.HTMLHeader :
<script>
function myFunction() {
alert('What a wonderful world');
}
</script>
For some reason it seems JavaScript functions and elaborate scripts do not execute in the HTML of a WebControlWrapper such as the WebHTMLArea project I modified.
Oh, BTW, important : I commented out the content of the ProcessHTML event except return html to avoid the control to mess with my HTML.