SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2001
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Load a window and validate on form submit

    I need to set up a form that once submitted opens a window thats 550x400.
    The form needs to be validated first however. I used an onClick event on the submit button but that opens the window regardless whether a user filled it out or not.

    Could anybody advise on the best way to get this done.
    Thanks

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put your validation in the onSubmit of the form, and add target="_blank".

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2001
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried this:

    <form method="post" action="/cgi-bin/FormMail.pl" name="Online_form" onSubmit="MM_validateForm('name','','R','email','','RisEmail','company','','R');return document.MM_returnValue" target="_blank">

    ended up opening two windows though. One going to formMail and the other went to the intended page without, this was whrn all inputs were left blank

  4. #4
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Something kinda like this?

    <html>
    <head>
    <script language="javascript">
    <!--
    // window opener from http://www.studiococo.com/index.asp?window.asp

    var x=0;

    function runCheck(loc)
    {
    for (i=0;i<loc.length;i++)
    {
    if (loc[i].length<1)
    {
    ++x;
    }
    else
    {
    //do nothing
    }
    }
    validate(loc);
    }

    function validate(loc)
    {
    if (x<loc.length)
    {
    alert("all fields have not been filled in");
    }
    else
    {
    SC_openWin(550,400,"test.html");
    loc.submit();
    }
    }

    function SC_openWin(width,height,url)
    {
    var newwin=window.open('" + url + "','newwin','width=" + width + ",height=" + height + ",top=10,left=10,menu=no,toolbar=no,directories=no,status=no,scrollbars=no,,dependent=no');
    }

    // -->
    </script>
    </head>
    <body>
    <form name="tester" method="post" action="whatever.pl">
    <!--tonnes of form stuff-->
    <input type="button" name="submit" value="Submit" onClick="runCheck(this.form)">
    </form>
    </body>
    </html>
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  5. #5
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That might work if you add target="newwin" to the form, but you should move the validation from the submit's onclick to the form's onsubmit, because you can press enter to submit the form. If it still doesn't work, the URL of the page would be helpful.

  6. #6
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    This script disables the enter button (at the cost of doing what is necessary) simply because using an actual submit button (notice this isn't a submit button) is more trouble than I felt it was worth.

    And, a new window is opened (from an encapsulated function) where the URL is specified. Thus, a target=_blank is unnecessary and would do what the previous solutions offered did: open 2 windows on occasion.
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  7. #7
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not having a submit button doesn't disable pressing enter to submit the form.

    I didn't say that a target=_blank was necessary, I said that a target=newwin was necessary. Yes, you did open a window in your "encapsulated" function, but it will have no effect on the form unless you specify the target to be newwin.

  8. #8
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Aright, well then I stand corrected regarding the submit...

    Add onSubmit="runCheck(this.form);" in there, remove the call in the button and make it a type="submit" and away you go.

    "I need to set up a form that once submitted opens a window thats 550x400."

    To me means he just wants this window open afterwards, not that he wants the results posted to the new window.

    Thus, my code should work, though feel free to post addendums and see if it meets with his approval, I'm just trying to help
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  9. #9
    SitePoint Zealot
    Join Date
    Jan 2001
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, Let me play with what you guys have given me.
    May take a me a little time to take it all in.
    Thanks!

    slowly but surely...

  10. #10
    SitePoint Zealot
    Join Date
    Jan 2001
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A solution!

    I simplified this. I first used dreamweaver to validate the form on onSubmit and redirected the user to a page where I placed an onLoad function. I also put a refresh in the meta tag to a specified URL for the parent window.

    Thanks studio and Anarch for your input, however I found that If i look inward I could find a way out

  11. #11
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    All the better and congrats on learning something new (especially something we hadn't thought of!)!
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright


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
  •