Running Html within Javascript

Discussion in 'JavaScript' started by blackwind, Oct 16, 2005.

  1. #1
    ok here's what I want to do.

    <script.....Java script...>

    if x=1
    {
    <div class="tools">
    <ul>
    <li><a href="#"><img src="images/tools.jpg" alt="tools" /></a>
    <ul>
    <li><a href="http://www.doink.biz/mail">E-mail</a></li>
    <li><a href="http://doink.biz/forum/index.php?&amp;act=Planner">Planner</a></li>
    <li><a href="http://doink.biz/forum/index.php?&amp;act=Planner&amp;code=contacts">Contacts</a></li>
    <li><a href="http://doink.biz/forum/index.php?&amp;act=Planner&amp;code=todo">To-do list</a></li>
    <li><a href="http://doink.biz/forum/index.php?&amp;act=Planner&amp;code=addnote">Notepad</a></li>
    <li><a href="http://doink.biz/textpattern/index.php">Admin</a></li>
    </ul>
    </li>
    </ul>
    </div>
    }
    else
    {
    }
    </script>

    Basically i want to run an html code if a condition is met. When I tried doing this it didn't work (probably because I'm running the html within JS tags.

    Do I need to insert something special to indicate that the following code is html...?

    Thanks.
     
    blackwind, Oct 16, 2005 IP
  2. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #2
    
    <script language="javascript">
    <!-- 
    if (1 == 2)
    {
         document.write('hell has frozen over');
    }
    else
    {
         document.write('Hello world ...');
    }
    // -->
    </script>
    
    HTML:
    i.e. you need to use the document.write() function to generate html output
     
    frankm, Oct 16, 2005 IP
  3. blackwind

    blackwind Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    document.write(<div class="tools">
    <ul>
    <li><a href="#"><img src="images/tools.jpg" alt="tools" /></a>
    <ul>
    <li><a href="http://www.doink.biz/mail">E-mail</a></li>
    <li><a href="http://doink.biz/forum/index.php?&amp;act=Planner">Planner</a></li>
    <li><a href="http://doink.biz/forum/index.php?&amp;act=Planner&amp;code=contacts">Contacts</a></li>
    <li><a href="http://doink.biz/forum/index.php?&amp;act=Planner&amp;code=todo">To-do list</a></li>
    <li><a href="http://doink.biz/forum/index.php?&amp;act=Planner&amp;code=addnote">Notepad</a></li>
    <li><a href="http://doink.biz/textpattern/index.php">Admin</a></li>
    </ul>
    </li>
    </ul>
    </div>);

    is that how you do it? (I also did it with single quotes (as in your example)) didn't work for me for some reason. am I missing something?
     
    blackwind, Oct 17, 2005 IP
  4. frankm

    frankm Active Member

    Messages:
    915
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    83
    #4
    If you want to do javascript, get a quick javascript reference guide.

    if you want to output multiple lines do this

    
    <script language=javascript>
    document.write('line1'+
       'line2'+
       'line3');
    </script>
    
    HTML:
    (all single quote, +-es and ; are needed)
     
    frankm, Oct 17, 2005 IP
  5. blackwind

    blackwind Peon

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Worked perfectly thanks so much!
    I definitely appreciate it.
     
    blackwind, Oct 17, 2005 IP