PDA

View Full Version : I need help making a simple javascript loop!


turdlewax
12-13-2001, 06:17 PM
I want to make a loop that will add   a certain amount of times to a 'document write' instruction.


document.writeln("<title>My Site" + Spaces() + "</title>")


I want a script that repeats &NBSP; a set number of times/loops and then writes it to that line, so that I can have a srting of spaces on my <TITLE>.

I'm a newbie to Javascript and this was my crappy go at it:


<head>

<script language=javascript type="text/javascript">


function Spaces(){
var one = i+1;
var numofspc = 50;
document.writeln("&nbsp;");Spaces();{
for (i;one){
if (i == numofspc);
}
return
}
}
document.writeln("<title>My Site" + Spaces() + "</title>")
</script>



</head>

Jon Hanlon
12-13-2001, 08:00 PM
function manySpaces(n) {
if (!n) n = 50 // default to 50
var nb = "&nbsp;"
var result = ""
for (var i=0; i<n; i++) out += result;
return result;
}

document.writeln("<title> My Page" + manySpaces(20) + "</title>");



Actually, I'm a big worried about the timing of this. I don't know whether all browsers will let you add a <title> element on the fly.
It might be better to do:
<title>my Page</title>
<body onload="document.title += manySpaces(20)">


Then again, Netscape 4 will probably balk at this.

So the burning question is, Just Why Do You Want To Do This?

turdlewax
12-13-2001, 08:10 PM
I wanted it so that I can move all the info after my title way off the bar. That and it helps to know a little more java now!