• Notice regarding image hosts and attachments. See here.

functions in JavaScript

Associate
Joined
25 Nov 2003
Posts
2,430
Location
Pub
I'm pretty new to programming and am doing an assignment where I need to be able to change a variable in a javascript programme. The global variable is already set but this has to be changed to whatever the user inputs via a window prompt. Where do I start?
 
Right, so start with your variable which has been set globally:

Code:
var varx = "value1";

Then create the function that asks input and shoves it in the variable:

Code:
function changeVar() {
varx = prompt("Text shown to the user","Default Value");
}

Then just run changeVar() whenever you need to change the variable.

For more information on JavaScript there are loads of tutorials on my website, see here: http://www.livescripts.net?tutorials/basjsindex.htm

Jon :cool:
 
Last edited:
Back
Top Bottom