Click to See Complete Forum and Search --> : Newbie question about specific code


Rylander
12-01-2003, 04:47 PM
Hello! I am a newbie at using javascript and I would love some help!

There is a slight snippet of a code I was wondering if you could help me decipher.. Below is something I just dont get.. What types of objects does this code refer to and what will be the result? I understand the 'thought' behind the code, but what do the lines mean? What do each line do?

I realise you guys must get these crappy questions all the time, and I more than understand if you dont wish to waste your time on it, but for all its worth - thank you for your time.
Anyway, here is the code!

function something_a(b) {
var s = document.f.s.value;
if (s != "") {
document[b].src = s;
}
}

PLEASE: If you do find time to help me with this, I would be *very* happy if you would email me, but it is of course not necessary since I have email notification... just a thought. Never mind... I am confused.

Cheers!

/ Andreas.

fredmv
12-01-2003, 05:06 PM
Welcome to the forums.// First, declare a function named something_a in which can accept one argument
// called b. The function would be called like this: something_a(foo) where foo is
// most likely a reference to another HTML element, more specifically, the name of it.
function something_a(b)
{
// Store a reference to a form element's value named s in the form named f.
var s = document.f.s.value;

// If the value of that form element is different than (!=) nothing...
if (s != "")
{
// Using the b argument passed to the function, access that element through the
// array of elements in the document and set it's src property to whatever value was passed.
document[b].src = s;
}
}

Rylander
12-02-2003, 12:58 PM
Thank you for your help, but I have so far restricted myself to theoretic use of javascript on pages... so I was wondering if you can exemplify? I think I understand the concept, but could you give me an example of when I would use such code, to obtain what result?

Thanks in advance

fredmv
12-02-2003, 01:43 PM
You're welcome. It appears to be a script intended for viewing images or something similar, at least that's what it seems like to me. Check the attachment for a demo.

Rylander
12-02-2003, 02:12 PM
Many thanks! No need to reply, just wanted to thank ya!