/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] multiple text box validation

Hi all

I have multiple text box and i want to validate it all through a single for loop and a if loop.

say :

<input name=”at1″ type=”text” class=”style7″ maxlength=”10″>
<input name=”at2″ type=”text” class=”style7″ maxlength=”10″>
<input name=”at3″ type=”text” class=”style7″ maxlength=”10″>

[QUOTE] <script=”javascript”>
for(i=1;i<=3;i++)
{
if(document.f.at[i].value.length==””)
{
alert(“Please fillup the A, T..Vid /+S/ DVD /GP”);
return false;
}
}
</script>[/QUOTE]

but in this way it is not validating

Can yopu plz suggest me what should i do now?

Thanks in advance…………Raj

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@RobDavidOct 27.2006 — try using this

if(document.forms['f']['at' + i].value.length=="")
Copy linkTweet thisAlerts:
@KorOct 27.2006 — you need a [B]function[/B],an [B]event[/B] to call that function, and a correct way to find the elements you are to apply the [B]methods[/B]. You need to define the type of your script. You need a lot of things, a Doctype, for instance...

A basic example could be based on [B]onsubmit[/B] event applied to the [B]form[/B] element, that means user will be alerted about the empty textbox the moment he will try to submit data to the server. And you must call for a returned Boolean value true/false on this attempt.

<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta http-equiv="Content-Style-Type" content="text/css"&gt;
&lt;meta http-equiv="Content-Script-Type" content="txt/javascript"&gt;
&lt;script type="text/javascript"&gt;
function valid(){
var i=1;
while(t=document.getElementsByName('at'+i++)[0]){
if(t.value==''){
alert('please fill the fields');
t.focus();
return false
}
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;form onsubmit="return valid()"&gt;
&lt;input name="at1" type="text" class="style7" maxlength="10"&gt;
&lt;input name="at2" type="text" class="style7" maxlength="10"&gt;
&lt;input name="at3" type="text" class="style7" maxlength="10"&gt;
&lt;br&gt;
&lt;br&gt;
&lt;input type="submit" value="Submit"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@raj_2006authorOct 27.2006 — hi

GREAT...its working

Thanks a lot mate.

luv

raj
Copy linkTweet thisAlerts:
@raj_2006authorOct 27.2006 — i used this one

if(document.forms['f']['at' + i].value.length=="")

also thanks a lot for another suggestion.

Cheers

Raj
Copy linkTweet thisAlerts:
@KorOct 27.2006 — I insist, for your good, to use the standard notation/coding, otherwise some browsers (and not a few) in this world will bring u errors. For instance:

<script [COLOR=Red]type="text/javascript"[/COLOR]>
Copy linkTweet thisAlerts:
@raj_2006authorOct 27.2006 — hi Kor

thanks for your posting too.....I understand to do universal standard coding i need to take care of the browsers compatibility.

Thanks for making me aware again.....Luv.....Raj
×

Success!

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