我在php中有自定义搜索表单。当我搜索任何产品时,将显示产品列表。
我可以使用复选框从搜索到的产品中选择任何产品。我有一个在变量中添加产品的按钮。
然后,我再次搜索其他产品。现在,我选择一个产品,然后单击按钮添加产品。我在新搜索中再次选择了1个值。
现在我有2个值。该搜索可以重复多次,但是该值必须存储在变量中,当我进入最后一步时,我可以使用所有选择的值。
当前,搜索新产品时,Value已从变量中删除。
我正在使用以下代码:
$(document).ready(function () {
//var final = '';
// open popup when click on Add Medicine button
var chkArray = [];
var addedDataArr = [];
var someVarName;
$('#addmedicine').click(function(){
/* look for all checkboes that have a class 'chk' attached to it and check if it was checked */
$(".checkboxclass:checked").each(function() {
chkArray.push($(this).attr('datanamemedicne'));
var textvalue = $(this).attr('mname');
});
/* we join the array separated by the comma */
var selected;
// selected = someVarName;
selected = chkArray.join(',') ;
if(selected.length > 0){
alert("You have selected " + selected);
}else{
alert("Please at least check one of the checkbox");
}
});
$("#nextform").click(function(){
$('#c82').val(chkArray);
$("#transferdetailform").fadeIn();
});
$("#cancelpopup").click(function(){
$("#transferdetailform").fadeOut();
});
});
<form id="search_doctor_form" action="<?php /* @escapeNotVerified */ echo $baseURL_l.'reorderform/index/search' ?>" onsubmit="return(valid());" method="get" name="search_form">
<div class="input-box">
<label for="search">Search</label>
<input id="search1" type="search" name="search" value="" class="input-text required-entry" maxlength="" placeholder="Search here...." />
<button type="submit" title="Search" class="button search-button" id="btn-search"><span><span>Search</span></span>
</button>
</div>
</form>
<ul class="pharmacy-list">
<li>
<input type="checkbox" class="checkboxclass" id="checkboxid" name="medicinecheck[]" value="1" datanamemedicne="Medicine ABC">
<span id="pharmacy-name-1" class="pharmacy-name" phone="1">Medicine ABC</span>
<span id="phamacy-price">500</span>
<span id="phamacy-image">image here</span>
</li>
<li>
<input type="checkbox" class="checkboxclass" id="checkboxid" name="medicinecheck[]" value="2" datanamemedicne="Medicine XYZ">
<span id="pharmacy-name-2" class="pharmacy-name" phone="1">Medicine ABC</span>
<span id="phamacy-price">250</span>
<span id="phamacy-image">image here</span>
</li>
</ul>
<input type="button" name="addmedicine" class="addmedicine" id="addmedicine">Add Medicne</button>
<input type="button" name="nextform" class="nextform" id="nextform">Next Step</button>