Javascript generating tags & body
Hi, I need help with Javascript syntax. Here is what I am trying to do: I am working on a webpage that is text-heavy. I want to make use of Netscape's <multicol> tag BUT, since some people don't like multiple columns, I want to make this optional. I also want to make it invisible for IE users. What I have tried to do is write a simple form that allows the person to choose "Multiple columns" or "Single column." I have written a form using "if document (layers)" so that only Netscape displays the form. Then I wrote the body of the text into Javascript so that Netscape generates the text surrounded by "multicol" tags, but IE writes it without the "multicol" tags. I realize that IE would just ignore the tags, BUT I need a third option where Netscape writes it without the "multicol". What I need is the syntax for a statement that says "if the document uses layers AND this radio button is checked then generate this text." I originally tried the following: if (document.forms[0].columns[0].checked) (then I wrote in the text surrounded by <multicol> tags). And then I added: if (document.forms[0].columns[1].checked) (text without <multicol> tags follows). But this didn't work, and it also gave an error in Internet Explorer (I think because Explorer couldn't find the form object). Here is my webpage & here is its source text. (This page isn't "live" so links don't work & this is dummy text/photos.) Does anyone know how I can write the if-then statement above to make this form actually do something? And is there a way I can write the body of text into a variable so I only have to spell out the whole text once? I'm afraid JavaScript isn't my strong point. Help would be appreciated! Thanks, Phyllis
A few hours later....
I realized I needed to use the "onClick" event handler to make this form work. Here is a new webpage & source text. This actually works except that it writes the text into a new document instead of the current page. Help!
[This message has been edited by phyllis (edited 02 April 2000).]
Lloyd Hassell posted this at 05:59 — 3rd April 2000.
They have: 231 posts
Joined: Feb 2000
Here is my suggestion. Instead of using a form, use a confirm box as the page is loading to ask Netscape users if they want multiple columns.
:: Lloyd Hassell :: http://www14.brinkster.com/lloydh ::
phyllis posted this at 13:09 — 3rd April 2000.
They have: 59 posts
Joined: Mar 2000
Thanks for the suggestion! I will give that a try. I could see why my own attempts wouldn't work but not how to fix them. I had hoped to somehow combine a script for show/hide layers with a function to write single or multiple columns, but I guess that's over my head -- I'm only just learning JavaScript. Anyway, thanks for the suggestion!
Phyllis
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.