/    Sign up×
Community /Pin to ProfileBookmark

Form Elements Validation

I am trying to do a form validation script. i am new to JScript and need some help.

here is one line of my code it always comes out true no matter what the value in the text box is.

if(weax.elements(1).value==””);{weax.elements(1).style.backgroundColor=”yellow”}

i am trying to loop through the numbers 1 to 50 and if the text area is blank then the feild turns yellow for text areas/boxes.

any ideas on what i am doing wrong?

thanks in advance.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@sciguyryanDec 12.2004 — Try this:

<i>
</i>&lt;script type="text/javascript"&gt;
&lt;!--
var Elements = document.getElementsByTagName("textarea");
for (var i = 0; i &lt; Elements.length; i++){
if (Elements[i].value == ""){
Elements[i].style.backgroundColor = "Yellow";
}
}
//--&gt;
&lt;/script&gt;



RyanJ
Copy linkTweet thisAlerts:
@batman93212authorDec 12.2004 — Hey Man,

thanks a lot. Now what would i do for a Textbox?
Copy linkTweet thisAlerts:
@sciguyryanDec 12.2004 — <i>
</i>&lt;script type="text/javascript"&gt;
&lt;!--
var Elements = document.getElementsByTagName("input");
for (var i = 0; i &lt; Elements.length; i++){
if ((Elements[i].type == "text") &amp;&amp; (Elements[i].value)){
if (Elements[i].value == ""){
Elements[i].style.backgroundColor = "Yellow";
}
}
}
//--&gt;
&lt;/script&gt;


Should work.


RyanJ
Copy linkTweet thisAlerts:
@CharlesDec 12.2004 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<meta name="Content-Style-Type" content="text/css">

<title>Example</title>

<style type="text/css">

<!--

form {width:15em}

fieldset {padding:1ex}

label {display:block; text-align:right}

button {display:block; margin:auto}

input.highlight {background-color:#ff0}

-->

</style>

<script type="text/javascript">

<!--

function check (f) {

var e, i = 0, correct = true;

while (e = f.elements[i++]) {if (e.type == 'text' && !/S/.test (e.value)) {e.className = 'highlight'; correct = false}};

return correct;

}

// -->

</script>

</head>

<body>

<form action="some-script.pl" onsubmit="return check (this)">

<fieldset>

<legend>Giant says</legend>

<label>Fee <input type="text"></label>

<label>Fie <input type="text"></label>

<label>Foe <input type="text"></label>

<label>Fum <input type="text"></label>

<button type="submit">Submit</button>

</fieldset>

</form>

</body>

</html>[/font]
Copy linkTweet thisAlerts:
@sciguyryanDec 12.2004 — WOW, thats an interesting way to do it, much smaller than mine.

Very useful Charles ?


RyanJ
Copy linkTweet thisAlerts:
@batman93212authorDec 12.2004 — Hey thanks for your help

i got it working.

This is the first time i asked a question and havent had some one make me feee 1ft tall.

once again thanks alot.

Ray
×

Success!

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