dongxi4235 2011-06-16 14:50
浏览 49
已采纳

jQuery Javascript组合列表

I am trying to create a form in which I can have a list and an input box/text box. What I want is when a user types in the text box a value and clicks add to the list, the value should be added to the list. Then once the person presses submit, the PHP code should be able to use the values obtained from list for procedure. I am trying to do it in PHP and HTML but a few have suggested jQuery in JS. Please help with what you know or how I can do this.

If you dont understand I have a diagram for what I want to do...

enter image description here

<?php
    $Fname = $_POST["Fname"];


    if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
    ?>


    <html>
    <head>
    <title>Personal INFO</title>


    <style type="text/css">
      body {
      background-image: url("http://dev.icalapp.rogersdigitalmedia.com.rogers-test.com/rogers_blackberry_8900.jpg");
      background-position: 50% 50%;
      background-repeat: repeat;
    }
    </style>



    </head>




    <body>
    <form method="post" action="<?php echo $PHP_SELF;?>">



    <span style="font-family:Helvetica;font-size:22px;font-style:normal;font-weight:bold;text-decoration:underline;text-transform:capitalize;color:FFFFFF;background-color:990033;">Amount of Numbers</span> <input type="text" style="text-align:center" size="12" maxlength="50" name="Fname" ><br />


    <input type="submit" value="submit" name="submit">
    </form>
    <?
    } 

    ?>
  • 写回答

2条回答

  • drfif48428 2011-06-16 15:10
    关注

    Try something like this:

    JS:

    $('#add').click(function(){
    
        var input = $('#addInput');
        var display = $('#display');
        var form = $('#addForm');
    
        if($.trim(input.val()).length > 0){ //is there input?
            display.append($('<p>',{text: input.val()}));
            form.append($('<input>',{value: input.val(), type: 'hidden', name: 'added[]'}));
            input.val('');
        }
    
    })
    

    HTML:

    <input id="addInput"/> <button id="add">Add</button>
    
    <div id='display'></div>
    
    <form action="something.php" id="addForm">
        <input type="submit" value="SUBMIT"/>
    </form>
    

    And then all of the things you add should be in an array called $_POST['added']

    DEMO: http://jsfiddle.net/maniator/aksEw/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)