/    Sign up×
Community /Pin to ProfileBookmark

Pass javascript variable to DIV

Hi all,
I have the following:

[code]
<script language=”javascript”>
<!–
function swapIt(chk) {
if(chk.value == “S”) document.getElementById(‘theRow’).style.visibility=”visible”;
document.getElementById(‘status’)=”StatusBar”;
else {
document.getElementById(‘theRow’).style.visibility=”hidden”;

}
if(chk.value == “E”) document.getElementById(‘theRow_2’).style.visibility=”visible”;
document.getElementById(‘status’)=”StatusBar_2″;
else {
document.getElementById(‘theRow_2’).style.visibility=”hidden”;

}
}

// –>
</script>
<DIV id=StatusBarContainer>
<DIV id=status>
<DIV id=”theRow_2″ style=”visibility:hidden”>
<table width=”100%” bgcolor=”#0000CC” cellpadding=”0″ cellspacing=”0″>
<tr><td>
<a href=”#” name=”ship_method” value=”S” onClick=”swapIt(this);”>Cancel</a>
</td></tr>
</table>
</DIV>
<DIV id=”theRow” style=”visibility:visible”>
<DIV id=StatusLeft>cartGURUS Administration – pmGURU (<a href=”admin/” >Dashboard</a> | <a href=”#” value=”E” onClick=”swapIt(this);”>Switch Projects</a>) </DIV>
<DIV id=StatusRight>
Logged in as
<?
include (“include/dbconnect.php”);
$cSQL = mysql_query(“SELECT first_name,last_name FROM admin WHERE admin_id = ‘” . $_SESSION[‘valid_admin’] . “‘”);
while ($row = mysql_fetch_array($cSQL)) {
echo $row[‘first_name’] . ” ” . $row[‘last_name’];
}
?>
(<A
title=”Log-out and clear the cookie off your machine”
href=”login.php”>Log-out</A>)
</DIV></DIV></DIV></DIV>
[/code]

All is working fine except when i try and pass the

[code]
document.getElementById(‘status’)=”StatusBar”;
[/code]

to the <DIV id=”status”> it doesn’t pass the value StatusBar or StatusBar_2 (depending on the condition).
Can anyone see where i am going wrong.
I don’t think this is written correctly

[code]
document.getElementById(‘status’)=”StatusBar”;
[/code]

Cheers,
camcim

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliMay 06.2004 — when you use

[b]document.getElementById('status')="StatusBar";[/b]

document has not idea what are you trying to do.

DIV element can not be assigned values like that.

It either has to be an attribute of this element such as id

document.getElementById('status').setAttribute("id","StatusBar");

of it has to be the text node in the div element in which case you can use

document.getElementById('status').innerHTML = "StatusBar";

in my opinion this second statement is what you might be trying to do.
×

Success!

Help @camcim spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...