Click to See Complete Forum and Search --> : script help needed
starrwriter
03-06-2003, 09:38 PM
I finally managed to assemble a simple script to generate CSS menus from form entries. I have text areas for 10 link entries (link text and URLs.) My problem is this: if you don't enter link data in all 10 text areas, the script generates code for empty table rows and screws up the bottom of the menu. What do I add to the script to keep it from generating table row data for the text areas that were left empty?
Post your code, please...
Vladdy
03-06-2003, 10:41 PM
var empty=/^\s*$/;
if(!empty.test(somestring))
starrwriter
03-07-2003, 11:38 AM
I finally managed to assemble a simple script to generate CSS menus from form entries. I have text areas for 10 link entries (link text and URLs.) My problem is this: if you don't enter link data in all 10 text areas, the script generates code for empty table rows and screws up the bottom of the menu. What do I add to the script to keep it from generating table row data for the text areas that were left empty?
Post your code, please...
Here it is:
<SCRIPT language=JavaScript>
<!--
function generate(xti){
document.formname.gencode.value='<!--Place this code in head section-->\n'+
'<style>\n'+
'A {\n'+
'color:'+xti.fontcolor.value+';\n'+
'text-decoration:none;\n'+
' }\n'+
'a:hover\n'+
'{color:'+xti.texthover.value+'; text-decoration:none;\n'+
'background: '+xti.cellhover.value+';\n'+
'display:block;\n'+
'}\n'+
'</style>\n'+
'<!--Place this code in body section-->\n'+
'<TABLE WIDTH="'+xti.menuwidth.value+'" BGCOLOR="'+xti.cellcolor.value+'" BORDER="1" BORDERCOLOR="black" CELLPADDING="2" CELLSPACING="0" ALIGN="left">\n'+
'<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link1url.value+'"><b>'+xti.link1name.value+'</a></p></b></font></TD></TR>\n'+
'<TR>\n'+
'<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link2url.value+'"><b>'+xti.link2name.value+'</a></p></b></font></TD></TR>\n'+
'<TR>\n'+
'<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link3url.value+'"><b>'+xti.link3name.value+'</a></p></b></font></TD></TR>\n'+
'<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link4url.value+'"><b>'+xti.link4name.value+'</a></p></b></font></TD></TR>\n'+
'<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link5url.value+'"><b>'+xti.link5name.value+'</a></p></b></font></TD></TR>\n'+
'<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link6url.value+'"><b>'+xti.link6name.value+'</a></p></b></font></TD></TR>\n'+
'<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link7url.value+'"><b>'+xti.link7name.value+'</a></p></b></font></TD></TR>\n'+
'<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link8url.value+'"><b>'+xti.link8name.value+'</a></p></b></font></TD></TR>\n'+
'<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link9url.value+'"><b>'+xti.link9name.value+'</a></p></b></font></TD></TR>\n'+
'<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link10url.value+'"><b>'+xti.link10name.value+'</a></p></b></font></TD></TR>\n'+
'</TABLE>\n';
}
//-->
</SCRIPT>
rodzilla
03-07-2003, 12:06 PM
Hello:
1. Looks like you forgot an opening <TR> tag.
2. You can merely add if's to each <TR>. So...
if (xti.link1.url.value && xti.link1name.value) {
document.writeln('<TR>\n<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link1url.value+'"><b>'+xti.link1name.value+'</a></p></b></font></TD></TR>\n');
}
if (xti.link2url.value && xti.link2name.value) {
document.writeln('<TR>\n'+
'<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link2url.value+'"><b>'+xti.link2name.value+'</a></p></b></font></TD></TR>\n'+
'<TR>\n');
}
etc.
starrwriter
03-07-2003, 02:54 PM
Originally posted by rodzilla
Hello:
1. Looks like you forgot an opening <TR> tag.
2. You can merely add if's to each <TR>. So...
if (xti.link1.url.value && xti.link1name.value) {
document.writeln('<TR>\n<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link1url.value+'"><b>'+xti.link1name.value+'</a></p></b></font></TD></TR>\n');
}
if (xti.link2url.value && xti.link2name.value) {
document.writeln('<TR>\n'+
'<TD><p align="center"><font face="Arial" size="2"><a href="'+xti.link2url.value+'"><b>'+xti.link2name.value+'</a></p></b></font></TD></TR>\n'+
'<TR>\n');
}
etc.
You're right, I forgot the opening TR tag, but it still worked for some reason. Thanks for the input. I'll give your idea a try and see if it works.
PS: I'm such a novice at javascript it's like trying to learn calculus if I could barely handle arithmetic.