doufei2355 2013-12-09 16:57
浏览 49
已采纳

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

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>
  • 写回答

4条回答 默认 最新

  • duanfen2349 2013-12-09 17:08
    关注

    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']; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?