Script problem, need some help

Discussion in 'JavaScript' started by izlik, Dec 6, 2008.

  1. #1
    Hello. The code posted bellow is a javascript wich makes me a nice little menu with buttons and shows diffrent text/links each time a button is pressed. (example here http://www.imagefrog.net/show.php/5857_domokun.jpg)

    Each time a button is pressed diffrent text appear and once a button is pressed i want another javascript the be displayed in plain text it's not supposed to be executed but as i said only shown in plain text if it's possible to do this, in the javascript code bellow it's the "Red" code i want to be shown as plain text and not get executed.

    <script language="JavaScript" type="text/javascript">
    var urlArray=new Array()
    urlArray[1]='[COLOR="Red"]<script> britepic_id="951875"; britepic_src="{IMAGEURL}"; britepic_keywords="image,hosting,free,imagefrog"; britepic_show_ads=1; britepic_show_menu=1; britepic_href="{ADSURL}"; britepic_caption="Hosted at http://Imagefrog.net"; </script> <script src="http://www.britepic.com/britepic.js"></script> <noscript><img src="{IMAGEURL}"></noscript>[/COLOR]';
    
    
    
    function setCode(id){
    	document.getElementById('info').value=urlArray[id];
    }
    
    
    function DispCode(id){
    	document.getElementById('tab1').className="";
    	document.getElementById('tab2').className="";
    	document.getElementById('tab3').className="";
    	document.getElementById('tab4').className="";
    	document.getElementById('tab5').className="";
    	document.getElementById('tab6').className="";
    	document.getElementById('tab'+id).className="activesubmit";
    	setCode(id);
    }
    
    </script>
    
    
    <table class="table_decoration" border="1" cellpadding="5" cellspacing="0" width="660" bordercolordark="#EEEEEE" bgcolor="#eeeeee">
    
    	<tbody><tr>
    
    		<td style="color: #111111">
    <div id="tabcontainer">
    	<ul id="tabs">
    		
    			<li class="activesubmit" id="tab1" onclick="DispCode(1);">ImageUrl</li>
    		
    			<li class="" id="tab2" onclick="DispCode(2);">Britepic</li>
    		
    		
    	</ul>
    	
    	
    	<div id="tabformcontent">
    			<textarea id="info" rows="11" cols="35" onclick="this.select();" readonly>{showurl}</textarea>
    	</div>
    	
    	<br class="clear" />
    	
    	</div>
    Code (markup):
     
    izlik, Dec 6, 2008 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    TEXTAREA doesn't have a VALUE attribute. Use innerHTML instead - and don't worry tags inside a textarea are not parsed or run.

    document.getElementById('info').innerHTML=urlArray[id];

    in your show function should do the trick.
     
    deathshadow, Dec 7, 2008 IP
  3. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #3
    where should i place "document.getElementById('info').innerHTML=urlArray[id];" ?? sorry im not so good with javascripts :/
     
    izlik, Dec 7, 2008 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #4
    replacing the very similar line inside function setCode(id).

    So where you have this:
    function setCode(id){
    	document.getElementById('info').value=urlArray[id];
    }
    Code (markup):
    You want this:
    function setCode(id){
    	document.getElementById('info').innerHTML=urlArray[id];
    }
    Code (markup):
    Should do the trick.
     
    deathshadow, Dec 7, 2008 IP
  5. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #5
    i just changed it but when i upload the file and go to it this is what i get this error bellow.

    '; urlArray[7]='/out.php/i5911_test.png'; function setCode(id){ document.getElementById('info').innerHTML=urlArray[id]; } function DispCode(id){ document.getElementById('tab1').className=""; document.getElementById('tab2').className=""; document.getElementById('tab3').className=""; document.getElementById('tab4').className=""; document.getElementById('tab5').className=""; document.getElementById('tab6').className=""; document.getElementById('tab'+id).className="activesubmit"; setCode(id); }
    Code (markup):
     
    izlik, Dec 8, 2008 IP
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #6
    I see code, but no error. What error?
     
    deathshadow, Dec 8, 2008 IP
  7. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #7
    a sorry should have said code not error. but that code appears on the top left corner of the page all the time where it should not be, and when i for example make spaces in the <script > and </ script> <--- like that it disappear from the top left corner of the page and appears in the other javascript button box shown above like it should. :/

     
    izlik, Dec 8, 2008 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #8
    I'd have to see the live example, or at least the complete code for the page for further diagnosis.

    Snippets are cute, but rarely reveal deeper rooted problems. From the table-heavy and presentational markup I'm willing to bet you have multiple validation errors, well formedness issues and a whole host of other things wrong on the page that are screwing up this relatively simple code.
     
    deathshadow, Dec 8, 2008 IP
  9. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #9
    i will send you a PM in a minute! :)
     
    izlik, Dec 8, 2008 IP