/    Sign up×
Community /Pin to ProfileBookmark

cant find a way to find text boxes who are null

my code

[code]
<!DOCTYPE html>
<!–
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
–>
<html>
<head>
<meta charset=”UTF-8″>
<title>Our Local site</title>
<script type=”text/javascript”>

function ab(){
var container = document.getElementById (“body”);
var abc = container.getElementsByTagName (“input”);
alert(“abc”);

}

</script>
</head>
<body>
<input id=”t1″type=”text” placeholder=”table name”><br>
<input id=”s1″type=”text” placeholder=”skill”>
<input id=”s2″type=”text” placeholder=”skill”>
<input id=”s3″type=”text” placeholder=”skill”>
<input id=”s4″type=”text” placeholder=”skill”>
<input id=”s5″type=”text” placeholder=”skill”>
<input id=”s6″type=”text” placeholder=”skill”>
<input id=”s7″type=”text” placeholder=”skill”>
<input id=”s8″type=”text” placeholder=”skill”>
<input id=”s9″type=”text” placeholder=”skill”>
<input id=”c1″type=”text” placeholder=”city”>
<input id=”c2″type=”text” placeholder=”city”>
<input id=”c3″type=”text” placeholder=”city”>
<input id=”c4″type=”text” placeholder=”city”>
<input id=”c5″type=”text” placeholder=”city”>
<input id=”c6″type=”text” placeholder=”city”><br>
<input id=”r1″type=”text” placeholder=”Region in city”>
<input id=”r2″type=”text” placeholder=”Region in city”>
<input id=”r3″type=”text” placeholder=”Region in city”>
<input id=”cn1″type=”text” placeholder=”country”>
<input id=”cn2″type=”text” placeholder=”country”>
<input id=”cn3″type=”text” placeholder=”country”>
<input id=”l1″type=”text” placeholder=”Latitude in degrees”>
<input id=”l2″type=”text” placeholder=”Longitude in degrees”>
<button id=”x” onclick=”ab()”>Click Me</button>

</body>
</html>
[/code]

i cant find a way to find textboxes that are empty upon clicking the button….

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@deathshadowMay 18.2014 — 1) might help if you had a PROPER form, since it's likely those input should be targeted/isolated by fieldset. EVEN when testing, I create the full and proper markup and for forms, a working submit, since again if you can't make a page that works without javascript FIRST, you likely have no business adding scripting to it.

2) Input values are not NULL, null is an object type indicating it is unassigned. What you probably meant to say was 'have an empty value'.

element.value == ''

3) why are you trying to create a copy of body if body is the parent? document.body -- done. Much less that since INPUT is invalid outside BODY (and technically invalid outside FORM... and depending on your doctype possibly invalid without a block level container around them like FIELDSET or DIV...)

4) if you are declaring multiple variables at once, you don't need to say VAR for each of them. Use a comma delimited list.


----------------------

'as is' with the garbage 'button', no proper form, outdated use of onclick...

function ab(){
var
inputList = document.getElementsByTagName("input"),
count = 0,
t;
for (t = 0; t &lt; inputList.length; t++) {
if (inputList[t].value == '') count++;
}
alert('There were ' + count + ' empty fields');
}


Though again, get proper complete and working markup BEFORE you start playing with scripting.
×

Success!

Help @ankit1122 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.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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