...

View Full Version : Javascript html generation.



Raraken
01-19-2006, 09:07 PM
I'm having a problem with a javascript function. It's made to add file fields dynamically to a small table. However, it works on firefox, but not internet explorer. In some of my changes trying to get it working, I my have fudged the remove function a bit.

Thank you for any help!


//------------------------------------------------------------------------------------
//
// HTML
//
//------------------------------------------------------------------------------------

<table class="sub_table" style="display: none;" cellspacing="0" id="comic_images">
<tr id="comic_upload">
<td style="padding-right: 14px;"><input type="file" name="image_upload[{row_id}]"></td>
<td nowrap><a href="javascript: remove_row('row_{row_id}')"><img src="cpanel/image_bin/icon_break.jpg" width="20" height="20" align="absmiddle">Remove
Image</a></td>
</tr>
<tr id="comic_existing">
<td style="padding-right: 14px;" nowrap><select name="image_exist[{row_id}]">
<!-- loaded_comics --><option value="{comic_id}" {selected}>{comic_name}</option><!-- /loaded_comics -->
</select></td>
<td nowrap><a href="javascript: remove_row('row_{row_id}')"><img src="cpanel/image_bin/icon_break.jpg" width="20" height="20" align="absmiddle">Remove
Image</a></td>
</tr>
</table>
<a href="javascript: add_row('upload');">Add Image (Upload) </a> | <a href="javascript: add_row('existing');">Add
Image (Pre-Loaded)</a>

<script>
<!--
var display_on = false;
var total_images = 0;
var row_upload = 0;

var str_tab = "comic_images";
var str_xst = "comic_existing";
var str_upl = "comic_upload";

var image_table = find_object(str_tab);
var img_tab_r_x = find_object(str_xst);
var img_tab_r_u = find_object(str_upl);

-->
</script>

//------------------------------------------------------------------------------------
//
// Javascript file (External)
//
//------------------------------------------------------------------------------------

function find_object(search_object) {
var p;
var i;
var found_object;

if( (p = search_object.indexOf("?")) > 0 && parent.frames.length) {
document = parent.frames[search_object.substring(p+1)].document;
search_object = search_object.substring(0,p);
}
if(!(found_object = document[search_object]) && document.all) {
found_object = document.all[search_object];
}
for (i=0; !found_object && i < document.forms.length; i++) {
found_object = document.forms[i][search_object];
}
for(i=0; !found_object && document.layers && i < document.layers.length; i++) {
found_object = findObj(search_object,document.layers[i].document);
}
if(!found_object && document.getElementById) {
found_object = document.getElementById(search_object);
}

return found_object;
}

function add_row (type) {
//document.writeln(image_table.innerHTML);
if (image_table.style.display == "none") {
image_table.style.display = "block";
go_table = find_object("comic_images");
image_table.innerHTML = '';
}

total_images ++;

if (type == 'upload') {
var fixed_upload = img_tab_r_u.innerHTML;
} else if (type == 'existing') {
var fixed_upload = img_tab_r_x.innerHTML;
}

while (fixed_upload.match("{row_id}")) {
var fixed_upload = fixed_upload.replace('{row_id}', total_images);
}

var image_upload = '<tr id="row_'+total_images+'">';
image_upload += fixed_upload;
image_upload += '</tr>';

image_table.innerHTML += image_upload;
refresh_page();
}

function remove_row (id) {
activate_display();
var image_row = null;
if (document.getElementById) {
image_row = document.getElementById(id);
} else if (document.all) {
image_row = document.all[id];
} else if (document.layers) {
image_row = document.layers[id];
}
image_row.innerHTML = '';
refresh_all();
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum