SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    save form values on closing windows

    hi
    am i right to post here the probs related to combination of php n js?
    well, the question is
    i have designed a form with some onclick function which opens a new window which has another form
    now what i want more is if i make submit in new form window, that new window shud get closed and the values to be saved and passed on to parent form window
    i am new to js,
    i have googled for this
    and got info for closing window but no-where abt saving my data and passing it to parent window
    any help wud be gr8ly appreciated
    thanx

  2. #2
    SitePoint Enthusiast Tygatur's Avatar
    Join Date
    Apr 2006
    Location
    Germany
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use this function to store the input of the form in a variable

    HTML Code:
    <script type="text/javascript">
    getstr="";
    function handleform(formular)
    {
    for(i=0;i<formular.elements.length;i++)
     {
     formele=formular.elements[i];
     if(typeof formele.options=='object')getstr+=formele.name+'='+formele.options[formele.options.selectedIndex].value+'&';
     else if(formele.type=='text'||formele.type=='textarea'||formele.type=='hidden')getstr+=formele.name+'='+formele.value+'&';
     else if(formele.type=='radio'||formele.type=='checkbox')if(formele.checked)getstr+=formele.name+'='+formele.value+'&';
     }
    getstr=getstr.slice(0,getstr.length-1);
    }
    </script>
    So simply set the action="" attribute of the popup form to
    HTML Code:
    <form id="fo" method="get" action="javascript:handleform(document.getElementById('fo'));alert(getstr);">
    And all of the input of the form will be scanned and handled by the function.
    Then change the last part of the action attribute (the alert(getstr) part) into a function, which will transmit the data to the parent window.
    For example

    opener.readmyform(getstr);

    Then the parent window fetches the variable getstr and can append it as GET-Data to the action="" attribute of parent form.

    p.s. nice nickname !
    Last edited by Tygatur; Jun 22, 2006 at 01:08. Reason: typos
    to code or not to code ?
    that's too much of a question for a signature.

  3. #3
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi
    thanx for the code
    just one more thing i wanna ask, can i display url part in that, i mean when the child window get displayed it doesn't show url
    r there any settings for that, in software??
    thanx once again


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
  •