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 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题