/    Sign up×
Community /Pin to ProfileBookmark

value change

i want to have a button thats value canges to a pre-defined variable when clicked but i dont know how to write it so far i’ve got

<HEAD>
<SCRIPT….>
….
var message = “jam”;
….
</SCRIPT>
</HEAD>
<BODY>
…….
<INPUT type=”button” value=”click” onClick=”this.value=message;”>
…….
</BODY>

but it just says there’s an error in the onClick part.
can you help or show an example???

if unclear just post to say and i will rectify

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsSep 11.2005 — it works ok
[CODE]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
</head>

<body >
<HEAD>
<SCRIPT>
var message = "jam";
</SCRIPT>
</HEAD>
<BODY>
<INPUT type="button" value="click" onClick="this.value=message;">
</BODY>
<br>
<br>

</body>

</html>
[/CODE]
Copy linkTweet thisAlerts:
@jamauthorSep 11.2005 — ok

but then i dont see why this doesn't work:


<HTML>

<HEAD>

<TITLE>

If You Don't Have A JavaScript Enabled Browser This Will NOT Work

</TITLE>

<SCRIPT Language="javascript">

<!--

var speed = 1000;

var msgNo = 0;

function messageChange() {

var msg1 = ">>>JAM<<<";

var msg2 = "..>>JAM<<..";

var msg3 = "....>JAM<....";

var msg4 = "......JAM......";

var finalMessage = "";

if (msgNo==0){

finalMessage = msg1;

msgNo = 1;

}

else{

if (msgNo==1){

finalMessage = msg2;

msgNo = 2;

}

else{

if (msgNo==2){

finalMessage = msg3;

msgNo = 3;

}

else{

finalMessage = msg4;

msgNo = 0;

}

}

}

window.status = finalMessage;

document.title = finalMessage;

}

window.onLoad = setInterval("messageChange();",speed);


//-->

</SCRIPT>

</HEAD>

<BODY>

<INPUT type="button" value="click" onClick="this.value=finalMessage;">

</BODY>

</HTML>

can u help?
Copy linkTweet thisAlerts:
@vwphillipsSep 11.2005 — [CODE]<HTML>
<HEAD>
<TITLE>
If You Don't Have A JavaScript Enabled Browser This Will NOT Work
</TITLE>
<SCRIPT Language="javascript">
<!--

var speed = 1000;
var msgNo = 0;

function messageChange() {

msg1 = ">>>JAM<<<";
msg2 = "..>>JAM<<..";
msg3 = "....>JAM<....";
msg4 = "......JAM......";
finalMessage = "";

if (msgNo==0){
finalMessage = msg1;
msgNo = 1;
}
else if (msgNo==1){
finalMessage = msg2;
msgNo = 2;
}
else if (msgNo==2){
finalMessage = msg3;
msgNo = 3;
}
else {
finalMessage = msg4;
msgNo = 0;
}
}
//-->
</SCRIPT>
</HEAD>
<BODY onload="messageChange();" >
<INPUT type="button" value="click" onClick="this.value=finalMessage;messageChange();">
</BODY>
</HTML>
[/CODE]
Copy linkTweet thisAlerts:
@CharlesSep 11.2005 — Because by using "var" when you defined "finalMessage" inside a function you made it a property of the call object. And the call object gets destroyed when the function returns. You want it to be a property of the Window object which it will be if you remove the "var". It would be, however, better programming to move the whole line to outside and above the function.
Copy linkTweet thisAlerts:
@jamauthorSep 11.2005 — cheers i've got it sorted it
×

Success!

Help @jam 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 4.28,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...