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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Working with forms

    I am working with javascript forms for an assignment. The goal is to be able to prompt for a input, check it, and then write it to the page or display it in a new pop-up window. So far I have the javascript correctly checking my data, but I can't figure out how to make it echo the results back.

    In the script I have a few testing functions to make sure the input is the correct form. They look something like...
    function isEmpty(elem) { } --checks to see if field empty
    function isValid(elem) {} --checks to see if field correct
    function validate(form){} --returns true if (isEmpty && isValid)

    In the body i have some code, listed below, that handles my input.
    <input type="text" size="30" name="name1" id="name1" onchange="if (isEmpty(this)) {isValid(this)}" /><br />
    <input type="submit" />

    I'm mostly just looking for a little guidance on how to declare an output function and where/how to call it.

    The simple examples I have looked up all seem to deal with input that isn't verified, and I can't quite figure out how to make that example work with what I am doing.

  • #2
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    What do you mean by output function? I guess you mean an alert()

    Anyway, please elaborate a little further, and show us the code and the markup so we could easily understand what your desire is.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • #3
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have reworked a fair amount of my code since making my first post.. so I'll try and make a more complete example of what my code looks like. I was trying to follow some form examples that I had found, and I think I was making some things more complicated then needed. Here is some more streamlined code.

    <head>
    foo

    <script type="text/javascript">
    <!--

    function isValid(elem) {
    var str= elem.value;
    var re = </foo$/>
    if (!str.match(re))
    {
    alert("abc");
    setTimeout("focuselement('" + elem.form.anem + "', '" + elem.name +"')",0;
    return false;
    }
    else
    {
    return true;
    }
    }

    function printData(?????) {
    document.write("The entry was: ");
    document.write(?????);
    }

    -->
    </script>
    </head>

    in the body I declare the following:

    Enter an amount:
    <input type="text" size="30" name="name1" id="name1" onchange="isValid(this)" /><br />
    <input type="submit" onclick="printData()" />

    This code is making sure my regular expression is in a correct form. It prints "The entry was: " so I know my function printData is doing at least something. However, it seems to me like I need to pass the validated regular expression to the printData(?????) function, that or I am typing the wrong thing in the document.write(?????) line.

  • #4
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    What are you trying to do? I'm confused.

    Also, don't use document.write, use nodeValue to add new value on your node instead.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph


  •  

    Posting Permissions

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