/    Sign up×
Community /Pin to ProfileBookmark

Function does not exist

I keep getting this error, even though the function does exist! I have

[code]
<script type=”text/javascript”>
function undo(){
alert(“undo”);
//some undo code here
}
</script>
….
<input value=”Undo” name=”undo” onclick=”undo()” type=”button”>
[/code]

When I click the button, I get an error saying function undo does not exist. But if I just call the function immediately after the page loads by putting

[code]
<script>
undo();
</script>
[/code]

At the bottom of my page, the alert box will pop up. I don’t know why clicking the button says the function doesn’t exist.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Arty_EffemOct 15.2007 — 
<i>
</i>&lt;input value="Undo" name="undo" onclick="undo()" type="button"&gt;


When I click the button, I get an error saying function undo does not exist. But if I just call the function immediately after the page loads by putting

<script>

undo();

</script>

[/code]

At the bottom of my page, the alert box will pop up.[/QUOTE]
Inside the form, the name of the button is in scope. Change its name.
Copy linkTweet thisAlerts:
@Declan1991Oct 15.2007 — I'm not sure, but if you add an id with the value "undo" to the tag, and try this:
[code=php]
document.getElementById("undo").onclick = undo;
[/code]

If that fails, try changing the name of the function.
×

Success!

Help @mizas 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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