/    Sign up×
Community /Pin to ProfileBookmark

(Newbie) Function is not defined ?

Hi guys,

I need your help with this problem , I checked the braces but it’s still not working.

Basically the code is based on 2 functions ( isNameOk,MainValidate ) to validate one input text triggered with OnBlur handler calling isNameOk function and passing “this” and getElementById of the span elemet (where the error msg will apear)

then isNameOk function passes (regex + input value + span ID + “error msg”) to MainValidate function were it checks the regex and decide to display error or not .
and when I run it , I get isNameOk function is not defined from the firefox error console !

i hope you get what I’m trying to do

[CODE]<html>

<head>

<script type=”text/javascript” src=”JavaScript.js”>

function MainValidate(regex, typed, errorId, Msg)
{
if (!regex.test(typed))
{
if (errorID != null)
while (errorID.firstChild)
{
errorId.removeChild(errorId.firstChild);
}
errorId.appendChild(document.createTextNode(Msg));
return false;
}

else
{
if (errorID != null)
{
while (errorID.firstChild)
{
errorID.removeChild(errorID.firstChild);
}
return true;
}
}
}

function isNameOk(input, errorID)
{

regex = /^[A-Za-z -]{2,10}s?([A-Za-z -]{2,10})?/
return MainValidate(regex, input.value, errorID, ” please enter valid name”);

}

</script>

</head>

<body>
<div>
Name :
<input id=”Name” type=”text” size=”20″ onblur=”isNameOk(this, document.getElementById(‘name_error’))” />
<span id=”name_error”></span>
</div>
</body>
</html>
[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KeverMay 14.2011 — A script tag pointing to an external file, doesn't run code between the tags.
&lt;script type="text/javascript" src="JavaScript.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
// internal code;
&lt;/script&gt;
Copy linkTweet thisAlerts:
@mixmanauthorMay 14.2011 — SOLVED

Thanks Kever for pointing this out, actually the code was external but I forgot to remove the src,

Anyways the problems is SOLVED just by changing the function name and parameters to lower case !!! I know that javascript case-sensitive but everything was a matching, maybe I should stop using upercase and lowercase mix words.


thanks again
×

Success!

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

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

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