fill out a form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • the1gofer
    New Member
    • Jun 2007
    • 6

    fill out a form

    I have a form on page A. I would like to have a pop up window with a search ( know how to do that), then once they find what they want and click it, have the appropriate fileds filled out on the form.

    I've seen it done on a php site, but I don't know if it was php or some other script. Any ideas?
  • Purple
    Recognized Expert Contributor
    • May 2007
    • 404

    #2
    Hi

    I suspect the site you have seen is using javascript to acheive this - try this..

    Code:
    //
    //	Function write2win : used by the lookup script to return the user selected value to the calling page
    //
    function write2win(form_name, field) {
      	var	choice = document.search.search_list.options[document.search.search_list.selectedIndex].value;
        opener.document[form_name][field].value = choice;
        opener.document[form_name].submit.click();
        window.close();
        }
    and in the lookup html insert a select button like :

    Code:
    <input type=\"submit\" value=\"OK\"  name=\"button\"
    			onClick=\"javascript:write2win('".$_POST['save_form']."','".$_POST['save_field']."');\">
    Regards Purple

    Comment

    • Purple
      Recognized Expert Contributor
      • May 2007
      • 404

      #3
      There is also a smarter way to do it using a javascript popup, take a look here at the dialogs => hello world example

      Purple

      Comment

      • the1gofer
        New Member
        • Jun 2007
        • 6

        #4
        Code:
        <input type=\"submit\" value=\"OK\"  name=\"button\"
        			onClick=\"javascript:write2win('".$_POST['save_form']."','".$_POST['save_field']."');\">
        Regards Purple[/QUOTE]


        I'm not to familar with javascript, so is this saving whatever information is the form? if I changed it to:

        Code:
        <input type=\"submit\" value=\"OK\"  name=\"button\"
        			onClick=\"javascript:write2win('"foobar','"foobar2."');\">
        and have it fill out a form with foobar and foobar2?

        Comment

        • the1gofer
          New Member
          • Jun 2007
          • 6

          #5
          a couple more questions.

          The button will be on page A, and the form it will fill out will be on Page B. Rite now the script reloads form A, how do redirect that.

          can I change the button to a link?

          Comment

          • Purple
            Recognized Expert Contributor
            • May 2007
            • 404

            #6
            Hi,

            if you don't want the button on the page, create a pixel big image, the same colour as the page background and use that then no one will see it..

            The write to win script runs on the second form (formB) and writes the value into the field whose name has been passed in the field parameter.


            Purple

            Comment

            Working...