/    Sign up×
Community /Pin to ProfileBookmark

What am I missing with this toggle?

Should be a simple toggle display, but seems to change only ONE time.
Any idea what I doing wrong?

[code]
<html>
<head>
<script type=”text/javascript”>

function changeLink2() {
var sel = document.getElementById(‘MyButton’); // alert(sel.value);
if (sel.value == ‘Changed to 1’) { sel.value = “Changed To 2”; }
else { sel.value = “Changed To 1″; }
}
</script>
</head>
<body>

<input id=”MyButton” type=”button” onclick=”changeLink2()” value=”Change link”>

</body>
</html>
[/code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERauthorAug 23.2011 — Figured out how to do it,

but I don't understand why this works and first post does not???
<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;

function changeLink2() {
var sel = document.getElementById('MyButton'); // alert(sel.value);
sel.value = (sel.value == 'Changed to 1') ? 'Changed to 2' : 'Changed to 1';
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;input id="MyButton" type="button" onclick="changeLink2()" value="Change link"&gt;

&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@TcobbAug 23.2011 — Its the difference between [CODE]if (sel.value == 'Changed to 1')[/CODE] and [CODE]sel.value = "Changed To 1"; }[/CODE]

Notice that in one case it is "to" and "To" in the other.
Copy linkTweet thisAlerts:
@JMRKERauthorAug 23.2011 — Its the difference between [CODE]if (sel.value == 'Changed to 1')[/CODE] and [CODE]sel.value = "Changed To 1"; }[/CODE]

Notice that in one case it is "to" and "To" in the other.[/QUOTE]


Thanks, that was driving me nuts. ?
Copy linkTweet thisAlerts:
@DracoMerestAug 23.2011 — Notice that in one case it is "to" and "To" in the other.[/QUOTE]

Good catch, I missed that both times I browsed the post. I was thinking of far

more esoteric reasons and forgot to KISS.
×

Success!

Help @JMRKER 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.29,
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,
)...