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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variable fro Javascript function to asp page 1

Status
Not open for further replies.

EdRev

Programmer
Aug 29, 2000
510
US
How can I pass a variable from a javascript onload function to the body of my asp page.

function onload()
{
var temp

if something == "x"{
document.all.note.style.color="red";
temp="RED";
}
else
}
document.all.note.styele.color="blue";
temp="BLUE"
}
}

<body onload="onload()";>
<span id ="note" name="note" style=".....">Note: You are now in the temp zone.</span>
 
The following interpretation of your code is more correct and will do what it is you want to do:
Code:
var something="x";
function onBodyLoad() {
  if (something == "x") {
    document.getElementById('note').style.color="red";
  } else {
    document.getElementById('note').style.color="blue";
  }
}
...
<body onload="onBodyLoad()">
<span id="note">Note:  You are now in the temp zone.</span>

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
BabyeJeffy
I think the word temp should read red or blue accordingly.

maybe try something like this...
Code:
var something="x";
function onBodyLoad() {
  if (something == "x") {
    document.getElementById('note').style.color="red";
    document.getElementById('temp').innerText="red";
  } else {
    document.getElementById('note').style.color="blue";
    document.getElementById('temp').innerText="blue";
  }
}
...
<body onload="onBodyLoad()">
<span id="note">Note:  You are now in the <span id="temp"></span> zone.</span>


Tony

Spirax-Sarco - steam traps control valves heat exchangers
Sun Villa - Luxury Florida accommodation
 
Thanks to all your response.

One more question though:

How can I substitute this variable

var color = "blue";
to

document.getElementById('temp').innerText="blue";

I did this and I'm getting NAN

document.getElementById('temp').innerText=+color;

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top