Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2006
    Posts
    7

    Unanswered: Auto-filling-in fields within a form

    Any help would be greatly appreciated. I'm trying to build-in auto-filling in of fields in my form.

    My form consists of standard fields, such as name, address, city, etc.

    Witin the form, I have a pull-down <SELECT> menu where the user selects a SKU. Upon making a selection, I'd like other fields such as 'product' to be filled in, depending on their selection. For instance, if they select "NCD01", I'd like to auto-fill-in the 'product' field as "Navigation CD". Finally, after the user fills in all other fields, they can click the Submit button.

    I tried making a "form within a form," whereby the <SELECT> field was a "sub-form" that redirects variables to the original script... but that didn't work.

    I'm completely lost as to how to construct/build this... does anyone have any general, or specific, guidance? Thank you in advance for your response.

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    Super-simplest method of doing this: Add an "onchange" event to your select. Have that handler figure out which data goes where based upon the selected option. Put that data into the form fields.

    Something along the lines of:
    PHP Code:
    <?php
    $theSKU 
    $_REQUEST['sku'];

    $some_text1 getValueFor($theSKU);
    ?>

    ...
    <form action="">
    ...
    <select name="sku" onchange="this.form.submit();">
         <option ...>
         .....
    <input type="text" name="some_text1" value="<?=$some_text1?>" />
    ...
    I think you also have to figure out which option from the select was selected and make sure that it is selected again on the page reload.

    I tried making a "form within a form," whereby the <SELECT> field was a "sub-form" that redirects variables to the original script... but that didn't work.
    Yea, I don't think you can have forms inside of forms.

  3. #3
    Join Date
    Feb 2006
    Posts
    7
    Thank you very much --- it makes sense. I'll give that a try!

  4. #4
    Join Date
    Mar 2006
    Posts
    1

    Funny you asked...

    I just wrote an article for the O'Reilly network about this:

    http://www.onlamp.com/pub/a/php/2006...ill-forms.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •