Javascript 存储-保存-获取/检索数组值(php)
我很难思考如何保存复选框中的值(来自“modalForm”)。 我这里有两张表格。我的“mainform”和“modalForm” 这些代码与我的程序类似,我只是替换了这些值 我的程序是这样工作的。我有一个搜索栏在此之前,搜索唯一的id和搜索后,他们的详细信息将加载在这里Javascript 存储-保存-获取/检索数组值(php),javascript,php,jquery,html,checkbox,Javascript,Php,Jquery,Html,Checkbox,我很难思考如何保存复选框中的值(来自“modalForm”)。 我这里有两张表格。我的“mainform”和“modalForm” 这些代码与我的程序类似,我只是替换了这些值 我的程序是这样工作的。我有一个搜索栏在此之前,搜索唯一的id和搜索后,他们的详细信息将加载在这里 如果单击文本框,将弹出一个包含复选框的模式。如果选中一个复选框,则其旁边的标签将显示在文本框上。选中两个或多个复选框时,UI中将显示“多个”一词。 值将插入/更新到数据库中 在我的例子中,文本框上显示的是值,而不是标签 您能帮
<form method="post" name="mainform" action="">
<label>Sports</label>
<a href="#modal" id="done"> <!-- when the input textbox was clicked, modal will pop up -->
<input disabled type="text" id="test" name="test" placeholder="test" value="">
<input class="hb_button3" type="submit" id="modalbutton" value="save"> <!-- once submit value taken on the checkbox will be save to the system database -->
</a>
</form>
<form method="post" name="modalForm" id="modalForm" action="testing.php">
<div class="modalwrapper" id="modal"> <!-- modal -->
<div class="modalcontainer">
<div class="modalcol1">
<label>Basketball </label>
<input type="checkbox" id="test_modal[]" name="test_modal[]" value="1">
<div class="clear"></div>
<label>Baseball </label>
<input type="checkbox" id="test_modal[]" name="test_modal[]" value="2">
<div class="clear"></div>
<label>Soccer </label>
<input type="checkbox" id="test_modal[]" name="test_modal[]" value="3">
<div class="clear"></div>
<label>Volleyball </label>
<input type="checkbox" id="test_modal[]" name="test_modal[]" value="4">
<div class="clear"></div>
<label>DOTA :)</label>
<input type="checkbox" id="test_modal[]" name="test_modal[]" value="5">
<div class="clear"></div>
<div class="savebutton">
<input class="btn1" id="submit" type="submit" value="Submit"/>
</div>
</div>
</div>
<div class="overlay"></div>
</div>
</form>
我的javascript代码
$(document).ready(function(){
$("#done").click(function(e) {
// alert('ok');
$("#modal").fadeIn();
// e.preventDefault();
});
$("#submit").click(function(e) {
var checked = [];
i=0;
temp=""
$("input[name='test_modal[]']:checked").each(function ()
{ temp=$(this).val();
i++;
checked.push($(this).val());
});
if (i==1)
$("#test").val(temp);
else if (i>1)
$("#test").val('multiple');
else if (i==0)
$("#test").val('nothing');
$("#modal").fadeOut();
// alert($("#do").val())
e.preventDefault();
});
});
希望你们能帮我。如果你们能建议使用任何php语句(如If-condition)替换我的javascript,我将尝试测试它。
非常感谢。下次再见。请注意你的拼写。对不起,下次请更新。请注意你的拼写。对不起,请更新。
$(document).ready(function(){
$("#done").click(function(e) {
// alert('ok');
$("#modal").fadeIn();
// e.preventDefault();
});
$("#submit").click(function(e) {
var checked = [];
i=0;
temp=""
$("input[name='test_modal[]']:checked").each(function ()
{ temp=$(this).val();
i++;
checked.push($(this).val());
});
if (i==1)
$("#test").val(temp);
else if (i>1)
$("#test").val('multiple');
else if (i==0)
$("#test").val('nothing');
$("#modal").fadeOut();
// alert($("#do").val())
e.preventDefault();
});
});