SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Misfit
    Join Date
    Apr 2000
    Location
    Pennsylvania, USA
    Posts
    2,266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Popping-up a form submission...

    Ok, I've got a problem. I'm designing this website that pops-up a window when you click on a link (does this for a few different links). The problem is, I need to pop-up a window when someone submits a form. Here's the code I use to pop-up a window:

    Code:
    onclick="NewWindow(this.href,'manage','600','300','yes');return false;"
    This is how it would normally work:

    Code:
    <a href="link.html" onclick="NewWindow(this.href,'manage','600','300','yes');return false;">
    Anyway, here's the form code:

    Code:
    <form action="/cgi-bin/reg_system.cgi" method="post"><input type="hidden" name="affiliate_id" value=""><input type="hidden" name="action" value="lookup"><input type="hidden" name="encoding_type" value=""><input type="text" name="domain" size="28" maxlength="67"><input type="image" src="http://www.dermains.com/images/submit.gif" width="70" height="20" border="0"></form>
    How would I integrate the Javascript code for the pop-up into that FORM code? I've tried lots of things, but nothing seems to work.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The DOM gives you access through JavaScript to all form attributes and elements. This is a little rough, but it should work.
    Code:
    function newWindow(the_form, attribute, another_attribute)  {
        loc = the_form.action + "?";  // this adds a ? to the end of the form action
        // This will loop through all of your form elements and concatenate a key=value onto the end of "loc" each time it executes
        for (i = 0; i < the_form.elements.length; i++)   {
            with (the_form)  {
               loc += elements[i].name + "=" + elements[i].value;
               // this will add an & only if this form element is not the last one 
               loc += (i != elements.length - 2) ? "&" : ""; 
            }
        }
        window.open(loc,"manage",your_window_attributes);
    }
    Now you don't need to use the button as a form element, just use it as a link like
    Code:
    <a href="javascript:newWindow(document.your_form);"><img src="button.gif"></a>
    Hope this helps. Post back if you need further assistance.
    Last edited by johnnydaboy; Jun 22, 2001 at 19:55.
    <<< johnny chidiac
    johnnydaboy@mac.com


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
  •