Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    check a form with an idea and no name

    hi.

    I got a XHTML 1.1 file and i want to post with it, and check if certain inputs are filled in or not, that worked fine with this code :

    <!--
    function checkformulier(veld)
    {
    loopdoor = false;
    while (true)
    {
    if (form1.naam.value== null || form1.naam.value=="" || form1.naam.value== form1.naam.defaultValue)
    {
    form1.naam.select();
    form1.naam.focus();
    break;
    }
    if (form1.message.value== null || form1.message.value=="" || form1.message.value== form1.message.defaultValue)
    {
    form1.message.focus();
    form1.message.select();
    break;
    }
    loopdoor = true;
    break;
    }
    if (loopdoor) {document.form1.submit()}
    }
    //-->
    GO TO THE LINK BELOW TO SEE THE FULL CODE

    but that worked when you use <form name="form1"> and i because i write xhtml i have to use <form id="form1"> and i have tried it with document.formID.elementname.value== null but thats not working. So does anybody know how to check a form with an idea and no name?

    check it out at http://www.generation.nl/~rewben/jn/

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    if you are using that function in many pages, you can make it generic by using document.forms[0] if you have only one form tag in a page.
    so to access a field, use:
    document.forms[0].naam.value

  • #3
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by glenngv
    if you are using that function in many pages, you can make it generic by using document.forms[0] if you have only one form tag in a page.
    so to access a field, use:
    document.forms[0].naam.value
    this is what i tried :

    <!--
    function checkform(veld)
    {
    loopdoor = false;
    while (true)
    {
    if (document.forms[0].naam.value == null || document.forms[0].naam.value=="" || document.forms[0].naam.value == form[0].naam.defaultValue)
    {
    form1.naam.select();
    form1.naam.focus();
    break;
    }
    if (document.forms[0].comment.value == null || document.forms[0].comment.value == "" || document.forms[0].comment.value == forms[0].comment.defaultValue)
    {
    forms[0].comment.focus();
    forms[0].comment.select();
    break;
    }
    loopdoor = true;
    break;
    }
    if (loopdoor) {document.forms[0].submit()}
    }

    //-->

    but didnt work, i can give the form an id though, so maybe somehow use getelementbyID ? But i dont know how to write my code then, i tried, but it wasnt working, but i think it was me

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    but you didn't change all and you use shortcut (forms[0]) in some lines.
    here is the modified code:

    function checkform(veld)
    {
    objForm = document.forms[0];
    loopdoor = false;
    while (true)
    {
    if (objForm.naam.value=="" || objForm.naam.value == objForm.naam.defaultValue)
    {
    objForm.naam.select();
    objForm.naam.focus();
    break;
    }
    if (objForm.comment.value == "" || objForm.comment.value == objForm.comment.defaultValue)
    {
    objForm.comment.focus();
    objForm.comment.select();
    break;
    }
    loopdoor = true;
    break;
    }
    if (loopdoor) {objForm.submit()}
    }

    the value of a textbox will never be null, so i removed the condition.
    btw, why do you have veld parameter in checkform() function but you are not using it inside the function?

  • #5
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow, thanks!

    it worked fine

    if you ever need some help with something just let me know.


    rewben@generation.nl
    http://www.generation.nl/~rewben/


  •  

    Posting Permissions

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