如何将值从一种形式传递到另一种形式?

I have this form:

<form name="summaryform">
      <select name="category" id="category" style="width:500px;">
        <option value="">Choose category...</option>
        <option value="ActionScript">ActionScript</option>
        <option value="AppleScript">AppleScript</option>
        <option value="Asp">Asp</option>
        <option value="BASIC">BASIC</option>
        <option value="C">C</option>
        <option value="C++">C++</option>
        <option value="Clojure">Clojure</option>
        <option value="COBOL">COBOL</option>
        <option value="ColdFusion">ColdFusion</option>
        <option value="Erlang">Erlang</option>
        <option value="Fortran">Fortran</option>
        <option value="Groovy">Groovy</option>
      </select><br>
      <select name="subcategory" id="subcategory" style="width:500px;">
        <option value="">Choose sub category...</option>
        <option value="Haskell">Haskell</option>
        <option value="Java">Java</option>
        <option value="JavaScript">JavaScript</option>
        <option value="Lisp">Lisp</option>
        <option value="Perl">Perl</option>
        <option value="PHP">PHP</option>
        <option value="Python">Python</option>
        <option value="Ruby">Ruby</option>
        <option value="Scala">Scala</option>
        <option value="Scheme">Scheme</option>
      </select><br>
  <input type="text" name="comments" id="comments" value="  Enter request comments..." onfocus="clearText(this)" onblur="restoreText(this)" style="width:493px;color:#999;font-size:9pt;height:20px;">

On the form above, I have two dropdowns (name="categoryId" and "subcategoryid") and one textboxt (name="comments")

How do I pass the values from this form to another form?

Let's say below is the form I want to pass the values to:

  <div>
    <p>
      <form name="summaryform" method='POST' action='process.php'>
      <div style="font-size:12pt;">
       value from one dropdown
       value from the other dropdown
       value from textbox
      </form>
    </p>
</div>

jQuery Method

If the forms are on the same page, you can use jQuery to get the values and write to the div:

var content = $('#category').val()+'<br>'+$('#subcategory').val()+'<br>'+$('#comments').val();
$('#div-to-write-to').html(content);

PHP Method

If the forms are on different pages, you will need to use PHP and the $_POST[] variable to pass the values you are looking for.

NOTE: for this method to work the page being POSTed to MUST be PHP. You will also need to add an action and method in the first form to POST to the second form.

This would be the code in the form on the page being POSTed to:

<?php echo $_POST['category'].'<br>'.$_POST['subcategory'].'<br>'.$_POST['comments']; ?>

A value can be passed between forms using the POST and GET methods. The first form (Which is sending the values) does not have this defined, so modify the first form to this -

<form name="summaryform" method='POST' action='process.php'>

Then, in process.php, put the following php code -

$dropdown_first = $_POST['category'];
$dropdown_second= $_POST['subcategory'];
$comment = $_POST['comments'];

After that, you can just use the variables as you see fit!

You can use post data fields to send the values to the next form

  1. If you want just print the selected values from first form @zsaa14's answer is good
  2. If you want to print whole select list, autoselected your value, heres a code.

foreach($categories as $category) {

$selected = $category['name'] === $_POST['category'] ? 'selected="selected"' : '';

echo " <option value="{$category['name']}" {$selected}>{$category['name']}</option>" ;

}

NOTE: the variable names and keys are for example, use Yours. This is only fragment of code.