I've getting the following error and I don't know how to fix it. I'm using codeigniter framework, I'm building an admin site, this side has a number of sections to administrate, in each section you can create, edit, translate or delete items. Each time I want to do any of these actions I get a form using Ajax, then I load it on a jquery Dialog, but if I want to include some javascript inside the dialog, it will load a total of 3 times, showing only the header of the dialog in the last 3 times. When I remove the javascript code inside the form, it loads perfect, just one time.
For instance, this is my news form:
<div id="create-form">
<?=form_open('news/'.$action); ?>
<?php $sindex = 0?>
<table class="table-content-right width800px" border="0" cellpadding="0" cellspacing="0">
<tr class="not-for-edit">
<td class="padding-10px" valign="top">
<span>SELECT LANG:</span>
</td>
<td class="padding-10px">
<select id="cmbTextTranslate" name="cmbTextTranslate">
<?php foreach($languages as $language) :?>
<?php if (($language->active == 1) && ($language->oid != $this->session->userdata('lang'))):?>
<option value='<?= $language->oid?>'><?= strtoupper($language->oid)?></option>
<?php endif;?>
<?php endforeach;?>
</select>
<img class="imgLangTranslate" src="" />
</td>
</tr>
<tr class="color-grey-soft-light color-black currentlang" valign="top">
<td class="padding-10px">TITLE: <img class="not-for-edit" src="<?=base_url()?>img/flags/en.gif" /></td>
<td class="padding-10px"><input id="title_en" name="title_en" class="input-border" type="text" value="<?= (isset($new) ? $new->title_en : "") ?>" /></td>
<td class="padding-10px"><span sindex="<?= $sindex++;?>" class="color-error"></span></td>
</tr>
<?php foreach($languages as $language) :?>
<?php if (($language->active == 1) && ($language->oid != $this->session->userdata('lang'))):?>
<tr class="not-for-edit" translateTo="<?= $language->oid?>" valign="top">
<td class="padding-10px" valign="top">TITLE_<?= $language->oid?>: <img class="translateToFlag" src="" /></td>
<td class="padding-10px" valign="top"><input class="input-border input-translate" id="title_<?= $language->oid?>" name="title_<?= $language->oid?>" type="text" value="<?= (isset($new) ? $new->title_es : "") ?>"/></td>
</tr>
<?php endif;?>
<?php endforeach;?>
<tr class="currentlang" valign="top"><td class="padding-10px">BODY: <img class="not-for-edit" src="<?=base_url()?>img/flags/en.gif" /></td>
<td id="textarea-td" class="padding-10px">
<textarea rows="5" id="body_en" class="input-border" name="body_en"><?= (isset($new) ? $new->body_en : "") ?></textarea>
</td>
<td class="padding-10px"><span sindex="<?=$sindex++;?>" class="color-error"></span></td>
</tr>
<?php foreach($languages as $language) :?>
<?php if (($language->active == 1) && ($language->oid != $this->session->userdata('lang'))):?>
<tr class="not-for-edit" translateTo="<?= $language->oid?>" valign="top">
<td class="padding-10px" valign="top">BODY_<?= $language->oid?>: <img class="translateToFlag" src="" /></td>
<td id="textarea-td_<?=$language->oid?>" class="padding-10px">
<textarea rows="5" id="body_<?=$language->oid?>" class="input-border" name="body_<?=$language->oid?>"><?= (isset($new) ? $new->body_es : "") ?></textarea>
</td>
</tr>
<?php endif;?>
<?php endforeach;?>
</table>
<input id="oid" name="oid" type="hidden" value="<?= (isset($new) ? $new->oid : "") ?>" />
</form>
And if I add the following block at the end of the file the error start:
<script type="text/javascript">
It doesn't matter if it is empty, or filled with code inside, it always give me the same error.
This is the code I have for calling that form:
$("#btnCreate").click(function(){
$.ajax({
type: 'GET',
dataType: 'html',
cache: false,
url: 'news/load_form/create',
success: function(data) {
//$(data).dialog(config.dialog);
$(data).dialog($.extend(config.dialog,
{title: 'CREATE NEW',
open: function() {
alert('cuantas veces');
},
close: function() {
$(this).dialog('destroy');
},
buttons: [
{ text:'CREATE',
click: function() {
if ($("form").submit() === true)
$(this).dialog("close");
}
},
{ text: 'RESET',
click: function() {
$("#create-form input[type='text']").val("");
}
},
{ text: 'CANCEL',
click: function() {
$(this).dialog("close");
}
}
]
})
);
$('.not-for-edit').hide();
tinyMCE.init($.extend(config.tinyMCE.writtable,
{oninit: function(){
setTimeout(function(){
tinyMCE.execCommand('mceRemoveControl', true, 'body_<?= $this->session->userdata('lang')?>');
tinyMCE.execCommand('mceAddControl', true, 'body_<?= $this->session->userdata('lang')?>');
}, 1000)}
})
);
}
});
});
I don't really understand the problem, it seems right to me. Thanks in advance.