SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot crunch42's Avatar
    Join Date
    Jun 2003
    Location
    San Francisco
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can I combine document.form.submit with window.open?

    I have a form with two submit buttons. One button works like a regular submit button and inserts a new record in a db. The second is a "preview" button. What I'd like to do when the Preview button is clicked is have the form contents posted into a popup window. Is this possible?

    My current code:
    PHP Code:
    <script type="text/javascript">
    function 
    submitFunction(i) {
       if (
    i==1document.form.action=
          
    "preview.php";
       if (
    i==2document.form.action=
          
    "insertrecord.php";
       
    document.form.submit()
       }
    </script>

    <input type="submit" name="Preview" value="Preview" onClick="submitFunction(1)">           
    <input type="submit" name="Publish" value="Publish" onClick="submitFunction(2)"> 
    So basically I want to combine the existing document.form.submit with something like a window.open, or any other way to open a popup window. Any ideas?

    Thanks,
    Julian

  2. #2
    SitePoint Zealot crunch42's Avatar
    Join Date
    Jun 2003
    Location
    San Francisco
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Figured it out...

    In case it helps anyone else:

    PHP Code:
    <script type="text/javascript">
    function 
    submitFunction(i) {
       if (
    i==1) { document.form.action"preview.php";
          
    document.form.target '_new';
          
    document.form.submit() }

       if (
    i==2) { document.form.action="insertrecord.php";
          
    document.form.submit() }
       }
    </script>
    <input type="submit" name="Preview" value="Preview" onClick="submitFunction(1)">           
    <input type="submit" name="Publish" value="Publish" onClick="submitFunction(2)"> 

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    407
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is exactly what I was looking for as well.
    Thanks for posting the answer


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
  •