Post by frufru~`'- on Dec 31, 2005 21:26:29 GMT -5
No, it's not ASP
This script will make the button open a window prompting for the rows and columns of the table, then inserting the table into the post with a row and column number in each for reference. Please note that there is no check for extra large numbers in inputs because that wastes the user's browser's resources, not your board's resources
Edit the red parts to suit your forum.
Demo
feel free to post (no spamming!)
Position: Global Footer
<script>
//Table generator replacing table button
//by frufru
var textcolor="FF0000"; //Text Color of popup window
var bgcolor="F1F1F1"; //background color of popup window
//dop not edit below
var thewindow;
if (document.postForm){
var thehtml="<html><head><title>Generate Table</title></head><body bgColor='" + bgcolor + "' text='" + textcolor + "'>Generate Table<br><form name='asdf' onSubmit='return false'>Rows: <input name=rows size=4> <br> Columns: <input name=columns size=4><input type=button value='Go' onClick='opener.addtable(document.asdf.rows.value,document.asdf.columns.value)'><br><b>Note: Entering extremely large numbers will slow down your browser, not the board.</b></body></html>";
var a=document.getElementsByTagName("a");
for (x=0;x<a.length;x++){
if (a[x].href=='javascript:add("[table][tr][td]","[/td][/tr][/table]")'){
a[x].href='javascript:blah()';
}
}
}
function blah(){
thewindow=window.open("about:blank","GenerateTable","width=200,height=200");
thewindow.document.write(thehtml);
}
function addtable(rows,columns){
var t="";
if (IsNumeric(rows) && IsNumeric(columns)){
thewindow.close();
t+="[table]";
for (x=0;x<rows;x++){
t+="[tr]";
for (y=0;y<columns;y++){
t+="[td]Row " + (x+1) + " Column " + (y+1) + "[/td]";
}
t+="[/tr]";
}
t+="[/table]";
add(t);
}else{
alert("Rows or columns are invalid");
thewindow.focus();
}
}
//the below code is a validation code taken from http://www.codetoad.com/javascript/isnumeric.asp
function IsNumeric(sText)
{
var ValidChars = "0123456789";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}
</script>
Thanks to Snakeair for the idea, and Ross for helping me get it working in IE ;D
This script will make the button open a window prompting for the rows and columns of the table, then inserting the table into the post with a row and column number in each for reference. Please note that there is no check for extra large numbers in inputs because that wastes the user's browser's resources, not your board's resources
Edit the red parts to suit your forum.
Demo
feel free to post (no spamming!)
Position: Global Footer
<script>
//Table generator replacing table button
//by frufru
var textcolor="FF0000"; //Text Color of popup window
var bgcolor="F1F1F1"; //background color of popup window
//dop not edit below
var thewindow;
if (document.postForm){
var thehtml="<html><head><title>Generate Table</title></head><body bgColor='" + bgcolor + "' text='" + textcolor + "'>Generate Table<br><form name='asdf' onSubmit='return false'>Rows: <input name=rows size=4> <br> Columns: <input name=columns size=4><input type=button value='Go' onClick='opener.addtable(document.asdf.rows.value,document.asdf.columns.value)'><br><b>Note: Entering extremely large numbers will slow down your browser, not the board.</b></body></html>";
var a=document.getElementsByTagName("a");
for (x=0;x<a.length;x++){
if (a[x].href=='javascript:add("[table][tr][td]","[/td][/tr][/table]")'){
a[x].href='javascript:blah()';
}
}
}
function blah(){
thewindow=window.open("about:blank","GenerateTable","width=200,height=200");
thewindow.document.write(thehtml);
}
function addtable(rows,columns){
var t="";
if (IsNumeric(rows) && IsNumeric(columns)){
thewindow.close();
t+="[table]";
for (x=0;x<rows;x++){
t+="[tr]";
for (y=0;y<columns;y++){
t+="[td]Row " + (x+1) + " Column " + (y+1) + "[/td]";
}
t+="[/tr]";
}
t+="[/table]";
add(t);
}else{
alert("Rows or columns are invalid");
thewindow.focus();
}
}
//the below code is a validation code taken from http://www.codetoad.com/javascript/isnumeric.asp
function IsNumeric(sText)
{
var ValidChars = "0123456789";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}
</script>
Thanks to Snakeair for the idea, and Ross for helping me get it working in IE ;D