Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a variable outside of a function

Status
Not open for further replies.

GiddyRob

Programmer
Aug 25, 2005
37
GB
Hi,

I am having a little trouble displaying a variable that's created in a function. I am using an onclick to pass a value from 1-4 depending on the link clicked. I have made the function check to see if the value is 1-4 then created 4 variations of the same variable. So:
if(a=1){
para='text';
}
if(a=2){
para='text';
}
etc

I want to be able to output the value of para anywhere I choose in my html. At the moment I am trying to output the variable in a div using document.write. I have set the variable para outside of the function to make it global, but it still does not work. I know the variable is working inside the function as i have tested it with alert to make sure I'm getting the right value.

any help on this would be great :)

Cheers

Rob
 
>if(a=1){
This is already wrong.
[tt]if(a=[red]=[/red]1){[/tt]
if you want to test the variable a.
 
sorry typo.

even if i put the variable outside of the if statements it still wont change when i click on a link.

I have set the variable with var outside to make it global and without var in the function so it should be global. The function is executing just doesn't seem to update the variable output when i use the document.write within the html.
 
? ok so how do I output the variable?

Can I run a line of code in the function to output to the div class?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top