Forum Moderators: open

Message Too Old, No Replies

Java inside Java

         

lindaw65

8:09 pm on Feb 13, 2009 (gmt 0)

10+ Year Member



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?

Thanks!

[edited by: eelixduppy at 5:38 pm (utc) on Feb. 14, 2009]
[edit reason] exemplified [/edit]

rocknbil

7:53 pm on Feb 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard lindaw65, two things.

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 [webmasterworld.com] and validate your pages [validator.w3.org], 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.

Fotiman

5:45 am on Feb 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Side note... Java is very different from JavaScript.

lindaw65

12:57 pm on Feb 16, 2009 (gmt 0)

10+ Year Member



Thanks. Still cannot get IE to behave. Here is the entire code if this helps. I just can't see why IE puts this sign in box at the bottom of the sidebar instead of where I tell it to. I removed the spacer.gif thinking that was causing the problem but it wasn't so I put it back. There has to be something my sleepy little brain is missing.

<!-- Begin

// NOTE: If you use a ' add a slash before it like this \'

document.write('<TABLE cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td align="center">');

// FLASH CHANGER OPTIONS

var notes1 = "yes" // SHOW 1ST NOTES
var notes2 = "yes" // SHOW 2ND NOTES
var sidewidth = "225" // SIDEBAR WIDTH
var pageheight = "125" // ADD HEIGHT TO ALL PAGES

var phone = "yes" // SHOW PHONE NUMBER
var phoneLR = "left" // phone LEFT OR RIGHT
var phoneX = "5" // phone X LOCATION
var phoneY = "5" // phone Y LOCATION

// 1ST NOTES AREA

if (notes1 == "yes") {
document.write('<fieldset><legend>');

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

document.write('Blurb Text<a href="webpage.htm">Contact us for more info.</a><br>');

document.write('</fieldset>');
document.write('<br><br>');
}

// 2ND NOTES AREA

if (notes2 == "yes") {
document.write('<fieldset><legend>');

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

document.write('<center>Blurb Text<br><br><script type="text/javascript" src="http://example.com/form/xx/4#*$!#*$!xx.js"></script><br>Blurb Text Again</center>');

document.write('</fieldset>');
document.write('<br><br>');
}

// START SIDEBAR MENU //

document.write('<TABLE cellpadding="0" cellspacing="0" border="0"><tr><td>');

document.write('<a href="website.htm" class="menuSidebar">Stuff</a>');

document.write('<a href="website.htm" class="menuSidebar">Stuff</a>');

document.write('<a href="website.htm" class="menuSidebar">Stuff Slideshow</a>');

document.write('</td></tr></table><br>');

// END SIDEBAR MENU //

// START PHONE NUMBER IN TOP MENU

// PAGEHEIGHT AND WIDTH SPACER (EDIT VARIABLES AT THE TOP)

document.write('<IMG SRC="spacer.gif" HEIGHT="'+pageheight+'" WIDTH="'+sidewidth+'" border="0"><br>');

document.write('</td></tr></table>');

// End -->

[edited by: eelixduppy at 5:01 pm (utc) on Feb. 16, 2009]
[edit reason] exemplified [/edit]

coopster

1:43 pm on Feb 16, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



At first glance here it looks as if your elements are not matching properly. For example, you seem to be closing a table at the very end that was never opened.

lindaw65

1:52 pm on Feb 16, 2009 (gmt 0)

10+ Year Member



The table begins under //Note. It's the main table for the sidebar.

coopster

2:16 pm on Feb 16, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have you tried inserting this code directly into your html for a moment rather than writing it out using JavaScript -- just long enough to validate it as suggested earlier? If it validates, then take it back out and don't forget you need to insert your external JavaScript (or your document.write statements) exactly at the point in your HTML where you expect it to render. I prefer using DOM methods as opposed to document.write but let's see if we can get you over this issue first.

lindaw65

2:51 pm on Feb 16, 2009 (gmt 0)

10+ Year Member



Yes it validates.

coopster

2:59 pm on Feb 16, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



OK, now that you have put just the HTML in there and it validates, now try inserting the JavaScript code directly into your web page at that point. Don't forget to wrap it in <script> tags.

lindaw65

3:02 pm on Feb 16, 2009 (gmt 0)

10+ Year Member



I was just doing that and it shows the same as with an external .js file. The submit box is at the bottom of the column.

coopster

5:20 pm on Feb 16, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



So, if you were to take all the HTML out of the document.write lines above, and insert the HTML from the included JavaScript file directly into your HTML document, does the code render the same, submit box at the bottom of the column? If so, have a look at your code and style again as something else may be rendering/displaying it where you do not expect.