Forum Moderators: open

Message Too Old, No Replies

learning javascript question

learning javascript question

         

spritch2

3:17 am on Jan 21, 2004 (gmt 0)

10+ Year Member



can anyone tell me why the linkURL variable has a + either side of it? the book i'm 'learning from' isn't very clear. are they creating a string?

linkURL = callingURL.substring(callingURL.indexOf('?')+1,callingURL.length)

document.writeln('<frame src="' + linkURL + '" name="content" \/>')

thanx

Purple Martin

5:37 am on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That whole line is getting a substring (part of a string) from the callingURL string and putting that value in linkURL.

The function to get a substring looks like this:

linkURL = callingURL.substring(...stuff...)

Look carefully at what goes in the brackets where I wrote ...stuff...

callingURL.indexOf('?')+1,callingURL.length

Do you see how it's got two parts separated by a comma? Good. Each part (we like to call them arguments) means something different. The first argument specifies where in callingURL to start getting the substring, and the second argument specifies where to stop getting the substring.

In this case, it's saying "start at the character AFTER the first character that is a question mark, and stop at the last character".

The +1 is the bit that says AFTER. That's because it'll find the question mark, and then one more is the character after the question mark.

I hope that makes sense! If not, search Google for a tutorial that explains substring() better than I can.

too much information

5:42 am on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wrong + sign ;)

Here's what's going on:
<frame src="' + linkURL + '" name="content" \/>

the linkURL is a string variable which contains the URL for the frame. It has the + signs on either side of it so that the writeln command knows that it isn't done with that line yet.

basically the entire line is saying:

Write '<frame src="' AND write the value of linkURL AND write '" name="content" \/>'

The \/ part tells the writeln command that the / is not the start of a special character.

Does that help?

*edited for clarification

spritch2

11:10 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



yeah, makes sense now cheers!