In the WYSIWYG editor I’m developing have a form table generator in a popup window. The table code is based form input (cols, rows, etc.) and is displayed in a textarea. This has to be copied and pasted into the source code of the web page under construction.
I want the table code to be inserted directly into the source code without copying and pasting it from the popup window. This would involve passing form output from a child window to an iframe embedded in the parent window. Any ideas on how would I script this?
<SCRIPT>
function makeTable() {
var rows = document.form.rows.value * 1
var cols = document.form.cols.value
var width = document.form.width.value * 1
var border = document.form.border.value
var cellpadding = document.form.cellpadding.value * 1
var align = document.form.align.value
var tdalign = document.form.tdalign.value
var bgcolor = document.form.bgcolor.value
if (bgcolor == “” || bgcolor == null) { bgcolor = “white” }
var valign = document.form.valign.value
var table = “<table width=”” + width + “”n”
table += ” border=”” + border + “”n”
table += ” cellpadding=”” + cellpadding + “”n”
table += ” align=”” + align + “”n”
table += ” bgColor=”” + bgcolor + “”n”
table += “n<!– –>nn”
var tdwidth = width / cols
for (i = 1; i <= rows; i++) {
table += “<!– Row ” + i + ” –>n”
table += “<tr>n”
for (t = 1; t <= cols; t++) {
table += “<td width=”” + tdwidth + “” align=”” + tdalign + “” valign=”” + valign + “”>n”
table += ” Row ” + i + “, Column ” + t +” n”
table += “</td>n”
}
table += “</tr>nn”
}
if (table.indexOf(“NaN”) != -1) {
table = “Sorry, there was an error generating your table.n”
table += “Please check all the fields and then try again.”
} else {
table += “</table>”
}
document.form.table.value = table //CHANGE THIS LINE TO WHAT?
document.form.table.focus() //ALSO CHANGE THIS LINE TO iframe.focus()?
}
</script>
<input type=”button” value=”Generate Code” onclick=”makeTable()”>
<br>
<textarea name=”table” rows=”10″ cols=”60″></textarea>