Results 1 to 2 of 2

Thread: cant find a way to find text boxes who are null

  1. #1
    Join Date
    May 2014

    cant find a way to find text boxes who are null

    my 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.
            <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");
            <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>

    i cant find a way to find textboxes that are empty upon clicking the button....
    Last edited by jedaisoul; 05-18-2014 at 06:34 AM. Reason: Code tags added

  2. #2
    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(){
    		inputList = document.getElementsByTagName("input"),
    		count = 0,
    	for (t = 0; t < 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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center