Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with if/then

    I started writing my very first javascript, but I've hit a wall. So far I have:

    Code:
    <script language="JavaScript" type="text/JavaScript">
    var link_list=new Array()
    link_list='<a href="http://www.cafepress.com/ultrageek/1335410/?pid=2489903">Astonomers Do It</a><br>'+
    	'<a href="http://www.cafepress.com/ultrageek/1335423/?pid=2489903">Astrophysicists Do It</a><br>'+
    	'<a href="http://www.cafepress.com/tvtee/1168647/?pid=2489903">Australians Do It </a><br>'+
    
    	'<a href="http://www.cafepress.com/ultrageek/1439447/?pid=2489903">Biologists Do It</a><br>'+
    	'<a href="http://www.cafepress.com/ultrageek/1439455/?pid=2489903">Botanists Do It</a><br>'+
    	'<a href="http://www.cafepress.com/niftetees/1406587/?pid=2489903">Bowlers do it </a><br>'+
    	'<a href="http://www.cafepress.com/tvtee/1168670/?pid=2489903">Bowlers do it </a><br>'+
    </script>

    Code:
    <script language="JavaScript" type="text/JavaScript">
    	function affiliate_sidebar(){
    document.write(link_list)
    }
    affiliate_sidebar()
    	</script>
    Now all I have to do is figure out how to have some default links displayed if there are none specified in var link_list. I thought maybe something along the lines of "if var link_list is undefined", but I don't have a clue if that would actually work or how to write it.

    Thanx in advance!

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Code:
    function affiliate_sidebar()
    {
     if (link_list.length < 1)
      {
      //Show default links/text
      }
     else
      {
      document.write(link_list)
      }
    }
    HTH
    Dan
    Last edited by whizard; 12-16-2006 at 05:04 PM. Reason: code typos
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •