Reputation: 7613
This has to be a simple question but I can't find the answer. I am trying to call my javascript function "Update_PointTracker_Account" within a modal so it executes when the modal is opened. For some reason it won't execute. However, the Onclick button calls the function perfectly. What am I doing wrong?
<div class="modal hide fade" id="Refresh_PointTracker_Program" data-keyboard="false" data-backdrop="static" aria-hidden="true">
<div class="modal-header" align='center'>
<h3>Refreshing PointTracker Program</h3>
</div>
<div class="modal-body" style="text-align: center">
<p> The points program is being refreshed</p>
</div>
<div style="text-align: center" id='updated_program_list'></div>
<script>
Update_PointTracker_Account();
</script>
<div class="modal-footer">
<button onclick ="Update_PointTracker_Account()" class="btn" aria-hidden="true">Update</button>
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
Upvotes: 0
Views: 130
Reputation: 1317
first: unless You are in a html5 doc You should add type attribute to script tag, second: the function exists? hope it helps
Upvotes: 0
Reputation: 121
Try to use a callback when you call your modal or verify if Update_PointTracker_Account()
is declared before the call.
Upvotes: 0
Reputation: 324790
I'm assuming this modal is being loaded with .innerHTML
somewhere.
<script>
tags do not run when inserted with innerHTML
. Instead, you should call the function when you assign the innerHTML
. The reason the button click works is because it's handled differently.
Upvotes: 1
Reputation: 66228
That is because you have not defined the function Update_PointTracker_Account()
at all.
It has to appear somewhere in the page, either as an inline JS or an imported JS file, and should look like:
function Update_PointTracker_Account() {
// Do something
}
Upvotes: 1