Javascript/PHP将复选框值添加到输入文本 [英] Javascript / PHP Add Checkbox Values to Input Text

查看:121
本文介绍了Javascript/PHP将复选框值添加到输入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个循环,其中包含数据库中的复选框值,当我选中某个复选框时,我需要将该值传递给输入(没有提交按钮);

I have a Loop with checkbox values from database and when I check some box I need that the value passes to the input (without submit button);

<?php

        while($row = $sth->fetch()) {

              echo("<input type='checkbox' value='".$row['name']."'>".$row['name']."</option>");
        }
        echo('<input type="text" name="modelos" />');

?>

谢谢

推荐答案

$(":checkbox").click(function(){
    var options="";
    $(":checkbox:checked").each(function(){
        options += $(this).val()+";"; 
    });

    $("input[name='modelos']").val(options);
});

在线演示: http://jsfiddle.net/ZPxqJ/6/

这篇关于Javascript/PHP将复选框值添加到输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆