/    Sign up×
Community /Pin to ProfileBookmark

Javascript Newbie

Hi Guys,

I am a total newbie to Javascript. I have a good knowledge in ASP and i have come to the stage where i need to intergrate some javascript into my code for things like form valiadtion.

Here is what i am trying to do(can you please comment on whether this is in the limits and help me out please)

I have got a form and what i want to do is check each element on the form. I want the Submit button of the form to only become active once all of the form elements have been completed/have some information in them.

Could anybody please help/advise how i would go about doing this.

My thanks in advance for any hlep you are able to give.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@DokJul 31.2007 — I don't like the approach - I would just validate when the user submits and if validation fails give pointers to what went wrong. This way you only have to validate once for each click on submit. With your approach you have to validate each time an input field changes. But here is how you do it
[code=html]<form method="post" action="whatever.asp">
Input 1: <input type="text" onchange="validate(event);" />
Input 2: <input type="text" onchange="validate(event);" />
Input 3: <input type="text" onchange="validate(event);" />
<input type="submit" disabled="disabled" />
</form>[/code]
The javascript function might look like
[CODE]function validate(e) {
// If IE
if (!e.target)
e.target = e.srcElement;
// Shortcuts
var inputs = e.target.elements;
var length = inputs.length;
for(var i=0; i<length; i++) {
// If any text input is empty return without enabling submit
if (inputs[i].type == "text" && !inputs[i].value)
return;
}
e.target.lastChild.disabled = false;
}[/CODE]
×

Success!

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

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

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