13 Replies - 926 Views - Last Post: 03 January 2013 - 05:56 AM

#1 matthijs--matthijs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-December 12

Changing text script problem

Posted 28 December 2012 - 05:34 AM

			<div class="footer">
				<ul>
					<li class="selected"><a href="index.html">Home</a></li>
					<li><a href="informatie.html">Informatie</a></li>
					<li><a href="prijslijst.html">Prijslijst</a></li>
					<li><a href="album.html">Foto album</a></li>
					<li><a href="contact.html">Contact</a></li>
				</ul>
						<script language="javascript">
							function textbar(){
								code_html = '<b>'+text[textid]+'</b>';    
								if(document.getElementById)    {
									document.getElementById("zone").innerHTML = code_html; 
								}   
								else if(document.all) {
								document.all["zone"].innerHTML = code_html;  
								}        
								if(textid == textview)        {
									textid = 0; // standaard op 0
								}        
								else  { 
								textid++; 
								}
								changement = 4; // verander hierboven de tijd dat de links moeten wisselen ( in milliseconden.. nu 4 )
							 
								window.setTimeout("textbar()", (changement*1000));
								} 
							// wil je meer teksten dan kan je deze invoegen door text[volgende nummer] = 'hier de tekst'; 
							text = new Array(); 
							text[0] = 'Tekst 1';
							text[1] = 'Tekst 2';
							text[2] = 'Tekst 3';
							text[3] = 'Tekst 4';
							text[4] = 'Tekst 5';
							text[5] = 'Tekst 6';
							text[6] = 'Tekst 7';
							text[7] = 'Tekst 8';
							textview = text.length-1;
							textid = 0; // standaard op 0 
						</script>
				<div id="zone">"textbar()"</div>
			</div>



What am I doing wrong? Probarly it's something in the "<div id="zone">"textbar()"</div>", because i'm pretty sure that the javascript code is good.

Btw,
here the css written by the javascript and changing text
.footer ul script{
display:none;
}
.footer #zone{
color:#5b5b5b;
font-size:10px;
font-family: Trebuchet MS;
font-weight:bold;
float:left;
margin:6px 0 0 250px;
}


Thanks for some responds!

Is This A Good Question/Topic? 0
  • +

Replies To: Changing text script problem

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,439
  • Joined: 08-June 10

Re: Changing text script problem

Posted 28 December 2012 - 06:47 AM

View Postmatthijs--matthijs, on 28 December 2012 - 01:34 PM, said:

What am I doing wrong? Probarly it's something in the "<div id="zone">"textbar()"</div>", because i'm pretty sure that the javascript code is good.

what is <div id="zone">"textbar()"</div> supposed to do? <div>s usually contain text or other HTML tags, but not executeable JS code.
Was This Post Helpful? 0
  • +
  • -

#3 matthijs--matthijs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-December 12

Re: Changing text script problem

Posted 28 December 2012 - 07:17 AM

View PostDormilich, on 28 December 2012 - 06:47 AM, said:

View Postmatthijs--matthijs, on 28 December 2012 - 01:34 PM, said:

What am I doing wrong? Probarly it's something in the "<div id="zone">"textbar()"</div>", because i'm pretty sure that the javascript code is good.

what is <div id="zone">"textbar()"</div> supposed to do? <div>s usually contain text or other HTML tags, but not executeable JS code.



Thats the problem, I have the JS code (Thats correct), but i don't get it visible, the <div id="zone">"textbar()"</div> was just a try to make it visible and changing.. But it didn't work. So I thaught is post it here, to get maybe a solution or some help on this.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,439
  • Joined: 08-June 10

Re: Changing text script problem

Posted 28 December 2012 - 07:30 AM

well, then letís get down to some JS-HTML basics:
- inside HTML, JS is only valid within the HTML event attributes and <script> tags
- JS is an event driven language, i.e. you can either execute JS at once, or assign an event handler that executes the JS when the event occurs.

so one of the simplest possibilities to execute your code is:
<div id="zone"></div>
<script type="application/javascript"> // the language attribute is deprecated!
function textbar(){
	// always declare local variables as such
	var code_html = '<b>'+text[textid]+'</b>';  
  
	// nowadays even IE supports document.getElementById
	document.getElementById("zone").innerHTML = code_html;

	// modulo to the rescue 
	textid = ++textid % text.length; 
}
// new Array() was yesterday, now itís its literal
text = ['Tekst 1', 'Tekst 2', 'Tekst 3', 'Tekst 4', 'Tekst 5', 'Tekst 6', 'Tekst 7', 'Tekst 8'];
textid = 0; // standaard op 0 

// and now run the function repeatedly:
window.setInterval(textbar, 4000);
</script>


Was This Post Helpful? 2
  • +
  • -

#5 matthijs--matthijs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-December 12

Re: Changing text script problem

Posted 28 December 2012 - 08:35 AM

Thanks, that made de script clearer for me.. So thank you!!
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,439
  • Joined: 08-June 10

Re: Changing text script problem

Posted 28 December 2012 - 08:36 AM

you could even leave out the <b> tags, as CSS can do that better.
Was This Post Helpful? 0
  • +
  • -

#7 matthijs--matthijs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-December 12

Re: Changing text script problem

Posted 28 December 2012 - 09:25 AM

I know.. I already did that ;)

But.. It is loading very slow.. You can see it atThis Site. Right under in the screen. It takes very long to load it, maybe you've got a solution for this?
Was This Post Helpful? 0
  • +
  • -

#8 matthijs--matthijs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-December 12

Re: Changing text script problem

Posted 28 December 2012 - 12:15 PM

Look window.setInterval(textbar, 4000);

On some reason the JS-code tells that the text only appears when the 4000 is past.

So after 4000 it appears and then it works fine

But i don't want that. It needs to appear directly
Was This Post Helpful? 0
  • +
  • -

#9 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,439
  • Joined: 08-June 10

Re: Changing text script problem

Posted 28 December 2012 - 12:20 PM

then call the function directly before that.
Was This Post Helpful? 0
  • +
  • -

#10 matthijs--matthijs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-December 12

Re: Changing text script problem

Posted 28 December 2012 - 12:25 PM

How you mean? Sorry i'm just a beginner with JS :$
Was This Post Helpful? 0
  • +
  • -

#11 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,439
  • Joined: 08-June 10

Re: Changing text script problem

Posted 28 December 2012 - 12:37 PM

textbar();
window.setInterval(textbar, 4000);

Was This Post Helpful? 0
  • +
  • -

#12 matthijs--matthijs  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-December 12

Re: Changing text script problem

Posted 28 December 2012 - 12:40 PM

You are a Hero!! Thank you very much!!!
Was This Post Helpful? 0
  • +
  • -

#13 fiddydips  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 20
  • Joined: 02-January 13

Re: Changing text script problem

Posted 02 January 2013 - 10:22 PM

Did that work? Right off the bat I see
<script language="javascript">
should be
<script type="text/javascript">
and text[textid], well textid is a variable and it looks like it might be out of scope. Every time you declare a variable, use
var name_of_variable = "value";


Don't be scared of JQuery, it's much more stable than regular javascript, and you can interchangeably use BOTH javascript and jquery at the same time, as it's just an extension / framework of js.
Was This Post Helpful? 0
  • +
  • -

#14 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3576
  • View blog
  • Posts: 10,439
  • Joined: 08-June 10

Re: Changing text script problem

Posted 03 January 2013 - 05:56 AM

View Postfiddydips, on 03 January 2013 - 06:22 AM, said:

[Don't be scared of] JQuery, it's much more stable than regular javascript

lol.

as you said, jQuery is Java​Script, hence it is as stable as JS. unless of course you define stability with cross-browser compatibility (and even that is not an issue of Java​Script (resp. the ECMAScript standard) but the browser’s implementation of ES).

This post has been edited by Dormilich: 03 January 2013 - 05:58 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1