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条)

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站