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 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))