/    Sign up×
Community /Pin to ProfileBookmark

A simple name check refuses to work

I have this simple code but it refuses to work. What do you think I’m missing here?

[code]
function check() {
var frm = document.getElementById(“formName”);

if (frm.fullName.value == “”) {
alert(‘Please Enter a valid Full Name’);
frm.fullName.focus();
return true;
}
}

<form id=”formName” action=”page.asp” method=”post” onsubmit=”return check();”>
[/code]

Thanks!

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJun 19.2006 — I would start with changing this:

<form id="formName" action="page.asp" method="post"

onsubmit="return check();">

to this:

<form [COLOR=Red]name[/COLOR]="formName" action="page.asp" method="post"

onsubmit="return check([COLOR=Red]this[/COLOR]);">

and your code to this:
function check([COLOR=Red]frm[/COLOR]) {
if (frm.fullName.value == "") {
alert('Please Enter a valid Full Name');
frm.fullName.focus();
return true;
}
}

Then, if it still fails, you have a field naming problem.
Copy linkTweet thisAlerts:
@weeeauthorJun 19.2006 — No change, it shows the alert and then automaticly redirect the page.

I can't use "name" 'cause I'm using:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

Gotta use "id".
Copy linkTweet thisAlerts:
@phpnoviceJun 19.2006 — Well, neither are required while using the [b]this[/b] keyword that I've got in there. ? Anyway... If the page is redirecting then you've got some other issues causing this. A live link to the entire page will be required.
Copy linkTweet thisAlerts:
@phpnoviceJun 19.2006 — By the way... To stop the form from submitting, you need this:
function check(frm) {
if (frm.fullName.value == "") {
alert('Please Enter a valid Full Name');
frm.fullName.focus();
return [COLOR=Red]false[/COLOR];
}
[COLOR=Red]return true[/COLOR];
}
Copy linkTweet thisAlerts:
@weeeauthorJun 20.2006 — It's working nice but only in IE and not FF.
Copy linkTweet thisAlerts:
@phpnoviceJun 20.2006 — None of the code posted here would affect Firefox. So, check for error messages:

Tools / JavaScript Console
Copy linkTweet thisAlerts:
@weeeauthorJun 20.2006 — Error: updateTime is not defined

Source File: http://mydomain.com/JS/home.js

Line: 147

And that's a whole different error for a different script.
Copy linkTweet thisAlerts:
@phpnoviceJun 20.2006 — Yep. Good luck.

Cheers.
Copy linkTweet thisAlerts:
@weeeauthorJun 20.2006 — Damn, I just fixed that smal but that wasn't relate to it and the form is working now!

Thanks phpnovice!!!
Copy linkTweet thisAlerts:
@phpnoviceJun 20.2006 — You're welcome.

Cheers.
×

Success!

Help @weee 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.19,
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,
)...