ownage Posted December 14, 2006 Share Posted December 14, 2006 i have a variable which is global, not in any funtions or whateva, straight at the top of the page. this is saved in a external file with a function. the page that is linked to this js page should onload open a function inside the external script and open a prompt box which then stores the input into my variable, then i want to use the variable input in another function which uses if etc,i have this code in my html page<code><body onclose="chooseme(a)" onload="prompta(a)"></code>this in my external file for prompta, i want to have the input sent to the global variable a in the end and im not sure how to do this and i think x=a isnt working ..., in c++ you use a ampersand before it and any modifications that are done get applied to that variable directly, its called passing the variable by refference, so function my(&x) would make all changes made to x in the function happen to the variable that was sent to it. <code>function prompta(x){x = prompt("What is the Password","get it right ")return x=a}</code>can some one tell me if this is correct, im wondering if you need to have {} around the statement after the if, and else if and else, you have to in c++ if u have more than one statement,<code>function chooseme(a){if(a="pword") closealert(a)else if(a="pword2") closealert2(a)elsedocument.write("<br /><br /><style="align: center">you have not got access =P</style>")}</code>variable is stated at top as<code>var a</code>i could have played around with my assumptions to see if it worked but i don't know if thats the error.im doubting the ability of external scripts... Link to comment Share on other sites More sharing options...
MrAdam Posted December 14, 2006 Share Posted December 14, 2006 yeah try: function chooseme(a){if(a="pword") { closealert(a)} else if (a="pword2") { closealert2(a)} else { document.write("<br /><br /><style="align: center">you have not got access =P</style>")} Link to comment Share on other sites More sharing options...
aspnetguy Posted December 14, 2006 Share Posted December 14, 2006 in the if statements use == not = Link to comment Share on other sites More sharing options...
jesh Posted December 14, 2006 Share Posted December 14, 2006 can some one tell me if this is correct, im wondering if you need to have {} around the statement after the if, and else if and else, you have to in c++ if u have more than one statement,Javascript works the same way - the following are equivalent:if(x == "test") alert(x); if(x == "test"){ alert(x);} Like C# (and I assume C++) you only need to use the braces if you have more than one statement in the if. But, like aspnetguy pointed out, you have to use == (equivalancy operator) rather than = (assignment operator). Link to comment Share on other sites More sharing options...
ownage Posted December 15, 2006 Author Share Posted December 15, 2006 - Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now