Java inside Java

Filed Under (Software Development) by admin on 17-02-2009

I have a client that wants to run a .js file inside a .js file because of the registration form. *(

if (notes2 == “yes”) {
document.write(‘<fieldset><legend>’);

document.write(‘Notes Area<br></legend>’);

document.write(‘<center>Blurb Text Here that shows up on webpage<br><br><script type=”text/javascript” src=”http://forms.example.com/form/XX/4#*$!#*$!xx.js”></script><br>More blurb text that shows up after the reg. box</center>’);

document.write(‘</fieldset>’);
document.write(‘<br><br>’);
}
)*

This code places the box where it should be in Firebox but in IE 7 the registration box is at the bottom of the table, not between the two text blurbs. Any idea how I can get this to show up in IE? if it’s “just not rendering” try breaking up the code. Weird things sometimes happen with Javascript within document.write.

document.write(‘<scr’+'ipt type=”text/jav’+'ascr’+'ipt” src=”http://forms.example.com/form/XX/4#*$!#*$!xx.js”></scr’+ipt>’);

Second, your formatting is likely a result of a combination of Quirks mode and deprecated tags/discouraged approaches to formatting. Use a valid document type and validate your pages, this will make 90% of your formatting problems go away, Javascript or not.

To solve that, here is how I’d handle this (but move inline styles to external style sheets.) You may have to insert text-align:center and width:400px (or some valid value) to get the effects you want:

document.write(‘<fieldset style=”margin:auto;”>’);
document.write(<legend>’Notes Area<br></legend>’);
document.write(‘<p style=”text-align:center”>Blurb Text Here that shows up on webpage</p>’);

document.write(‘<div style=”margin:auto;”>’);
document.write(‘<scr’+'ipt type=”text/jav’+'ascr’+'ipt” src=”http://forms.example.com/form/XX/4#*$!#*$!xx.js”></scr’+ipt>’);
document.write(‘</div>’);

<!–
if you still have problems
add document.write(‘<div style=”clear:both;”></div>’);
right here
–>

document.write(‘<p style=”text-align:center”>More blurb text that shows up after the reg. box</p>’);
document.write(‘</fieldset>’);

Note the clearing div, you probably won’t need it, or can set the last p to clear, or overflow: none on the div containing the script – but overall, Standards Mode and semantic output should help you.

Comments are closed.