SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using loops to check a form

    Hi there,

    I'm trying to write a JavaScript loop to ensure that the half dozen fields of my form are populated before the processing script is called.

    I could get JS to check each of the fields individually, but I'd really like to use a loop to streamline my code.

    Could anybody help please?

    Thanks,

  2. #2
    SitePoint Guru SSJ's Avatar
    Join Date
    Jan 2007
    Posts
    828
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try Following Function:

    Code:
    <script type="text/javascript">
    function DisplayFormValues()
    {
    var str = '';
    var elem = document.getElementById('formName').elements;
    for(var i = 0; i < elem.length; i++)
    {
    str += "<b>Type:</b>" + elem[i].type + "&nbsp&nbsp";
    str += "<b>Name:</b>" + elem[i].name + "&nbsp;&nbsp;";
    str += "<b>Value:</b><i>" + elem[i].value + "</i>&nbsp;&nbsp;";
    str += "<BR>";
    }
    document.getElementById('lblValues').innerHTML = str;
    }
    </script>


Bookmarks

Posting Permissions

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