I just wonder if somebody has met this problem. I need to call a
javaScript function within "<tr.....>".
{% for v in data %}
<tr class="odd"
id="{{v.publisher_id}}"
<script type="text/javascript"
language="JavaScript">
showDomainTable
('{{v.publisher_id}}', '{{v.country_id}}');
</script>
>
This works well with Firebox but not with IE 8. IE just prints
"showDomainTable(...)" instead of calling it.
Any help? Thanks so much.
<tr class="odd" id="{{v.publisher_id}}">
<script type="text/javascript">
showDomainTable('{{v.publisher_id}}', '{{v.country_id}}');
</script>
</tr>
But even then, inline javascript is something better avoided. I would
just create a function that is run as soon as the document is loaded,
find all tr's inside your table, and use their id's to call your
showDomainTable function. If you also need the country id, something
like this could work:
<tr class="odd" id="{{v.publisher_id}}_{{v.country_id}}">
And then in your javascript code just split on the underscore.
I have no clue if you know jQuery? But this would be very easy if you
would use jQuery. If you need it, I could give you some mockup code to
help you along.
Especially, in this case, because there is no garantee whatsoever that
the element has already been created and added to the document's DOM.
Thanks so much for your replies. Following your suggestions I have
moved tag <script> out of <tr>.
<tr class="odd" id="{{v.publisher_id}}">
<script type="text/javascript">
showDomainTable('{{v.publisher_id}}', '{{v.country_id}}');
</script>
</tr>
Sorry I do not know jQuery. For the moment let me follow your
suggestions and move forward. If I can not succeed then I will
consider jQuery.
Thanks again. Appreciated.
On Dec 28, 2:31 am, Masklinn <maskl...@masklinn.net> wrote:
Sorry I could not make progress therefore I am considering to use
jQuery. As I never used it, can I have your jQuery code for reference?
You may send to my e-mail gilb...@gamil.com
Thanks so much.
> > the element has already been created and added to the document's DOM.- Hide quoted text -
>
> - Show quoted text -
Create a new javascript file, and put the following code in it:
// This is automatically run when the document has been completely
loaded
$(function() {
// Find all tr's in your table (give your table an id)
$('#your_table_id tr').each(function() {
// Give your tr's an id like {{v.publisher_id}}_
{{v.country_id}}
// We now split that id on the underscore and get the parts we
need.
temp = this.id.split('_');
publisher_id = temp[0];
country_id = temp[1];
// Call your function however you like
showDomainTable(publisher_id, country_id);
});
});
Include this new javascript in your template too, and give your table
an id.
This code is just from the top of my head, but it should work alright.
On Dec 28, 11:24 pm, "gilbert F." <gilber...@gmail.com> wrote:
> Hi Kevin,
>
> Sorry I could not make progress therefore I am considering to use
> jQuery. As I never used it, can I have your jQuery code for reference?
> You may send to my e-mail gilber...@gamil.com