I am trying to get values Y and N on change switchery button, but with the following piece of codes whatever I've written, I am getting 'Y' all the time. please help
var lang_dis_button = document.querySelector('.lang-disable');
var lang_disable = new Switchery(lang_dis_button, { color: '#ED5565' });
var changeStatus = document.querySelector('.lang-disable')
, changeField = document.querySelector('#disabled_status');
changeStatus.onchange = function() {
if (changeStatus.checked) {
changeField.innerHTML = 'Disabled';
} else {
changeField.innerHTML = 'Active';
}
};
<input type="checkbox" class="lang-disable" name="disabled" id="disabled" value="Y"
<?php IF ($disabled == 'Y') { ?> checked><label id="disabled_status">Disabled</label><?php }
else { ?><label id="disabled_status">Active<?php } ?></label>
The problem in question is not to allow me to click on a checkbox if the atendimento number (atendimento.value) is different from a previously entered number.
When I first click on 1 checkbox I store this value and a push to an array.
If I click on another checkbox and the atendimento.value is different, it will display the error message with toast.
I would like to know what I'm forgetting / missing in my code.
ng.checkAtendimento = function(id) {
var atendimento = document.getElementById('atendimento-' + id);
var checkOs = document.getElementById('checkOs-' + id);
var array = [];
if(checkOs.checked){
array.push(atendimento.value);
console.log(array);
}else{
var index = array.indexOf(atendimento.value);
array.splice(index, 1);
console.log(array);
}
if(array[0] != atendimento.value){
console.log(array[0]);
toastr.error(
'error',
'service', {
closeButton: true,
progressBar: true,
timeOut: 7000
});
checkOs.checked = false;
}
}
HTML/PHP
<input id="checkOs-<?php echo $entity->getId(); ?>"
ng-click="checkAtendimento('<?php echo $entity->getId(); ?>');"
type="checkbox"
class="array-ordemservico"
name="[]array-ordemservico"
value="<?php echo $entity->getId();?>" />
<input id="atendimento-<?php echo $entity->getId(); ?>"
class="array-atendimento"
style="display:none" type="checkbox"
value="<?php echo $entity->getAtendimento(); ?>" />
ng.checkAtendimento = function(id){
var atendimento = document.getElementById('atendimento-' + id);
$("#checkOs-" + id).on("change", function (){
index = $.inArray(atendimento.value, ArrayCheckbox);
if ($("#checkOs-" + id).prop('checked')){
if (ArrayCheckbox.length > 0 && index === -1 && atendimento.value != ""){
toastr.error(
'error',
'OS',{
closeButton: true,
progressBar: true,
timeOut: 7000
});
$("#checkOs-" + id).prop("checked", false);
} else if(ArrayCheckbox.length == 0 && atendimento.value != ""){
ArrayCheckbox.push(atendimento.value);
}
} else if((ArrayCheckbox[0] == atendimento.value)){
ArrayCheckbox.splice(index, 1);
}
});
}
I'm performing multiple delete records operation using jQuery and php currently i'm able to delete single / multiple records by clicking on checkbox its working fine as of now but my page gets refreshed every time i delete record because im not using ajax.
I'm a beginner in ajax I want to perform this same operation using JQUERY/AJAX which will not make my page reload every time i delete my record so i want to use ajax for the same code so that i can handle my page reload.
Somebody help me out in achieving it Thanks!!
HTML/PHP
<form method="post" name="data_table">
<table id="table_data">
<tr>
<td>Name</td>
<td>Select All <input type="checkbox" id="check_all" value=""></td>
</tr>
<?php
$query = mysql_query("SELECT * FROM `products`");
while($row = mysql_fetch_array($query))
{
?>
<tr>
<td>
<?php echo $row['product_title']; ?>
</td>
<td>
<input type="checkbox" value="<?php echo $row['id'];?>" name="data[]" id="data">
</td>
</tr>
<?php
}
?>
</table>
<br />
<input name="submit" type="submit" value="Delete" id="submit">
</form>
JQuery
jQuery(function($)
{
$("form input[id='check_all']").click(function()
{
var inputs = $("form input[type='checkbox']");
for(var i = 0; i < inputs.length; i++)
{
var type = inputs[i].getAttribute("type");
if(type == "checkbox")
{
if(this.checked)
{
inputs[i].checked = true;
}
else
{
inputs[i].checked = false;
}
}
}
});
$("form input[id='submit']").click(function()
{ var inputs = $("form input[type='checkbox']");
var vals=[];
var res;
for(var i = 0; i < inputs.length; i++)
{
var type = inputs[i].getAttribute("type");
if(type == "checkbox")
{
if(inputs[i].id=="data"&&inputs[i].checked){
vals.push(inputs[i].value);
}
}
}
var count_checked = $("[name='data[]']:checked").length;
if(count_checked == 0)
{
alert("Please select a product(s) to delete.");
return false;
}
if(count_checked == 1)
{
res= confirm("Are you sure you want to delete these product?");
}
else
{
res= confirm("Are you sure you want to delete these products?");
}
if(res){
/*** This portion is the ajax/jquery post calling ****/
$.post("delete.php", {data:vals}, function(result){
$("#table_data").html(result);
});
}
});
});
PHP delete code
<?php
if(isset($_POST['data']))
{
$id_array = $_POST['data']; // return array
$id_count = count($_POST['data']); // count array
for($i=0; $i < $id_count; $i++)
{
$id = $id_array[$i];
$query = mysql_query("DELETE FROM `products` WHERE `id` = '$id'");
if(!$query)
{
die(mysql_error());
}
}?>
Please do the changes jquery as
jQuery(function($)
{
$("form input[id='check_all']").click(function()
{
var inputs = $("form input[type='checkbox']");
for(var i = 0; i < inputs.length; i++)
{
var type = inputs[i].getAttribute("type");
if(type == "checkbox")
{
if(this.checked)
{
inputs[i].checked = true;
}
else
{
inputs[i].checked = false;
}
}
}
});
$("form input[id='submit']").click(function()
{ var inputs = $("form input[type='checkbox']");
var vals=[];
var res;
for(var i = 0; i < inputs.length; i++)
{
var type = inputs[i].getAttribute("type");
if(type == "checkbox")
{
if(inputs[i].id=="data"&&inputs[i].checked){
vals.push(inputs[i].value);
}
}
}
var count_checked = $("[name='data[]']:checked").length;
if(count_checked == 0)
{
alert("Please select a product(s) to delete.");
return false;
}
if(count_checked == 1)
{
res= confirm("Are you sure you want to delete these product?");
}
else
{
res= confirm("Are you sure you want to delete these products?");
}
if(res){
/*** This portion is the ajax/jquery post calling ****/
$.post("delete.php", {data:vals}, function(result){
$("#table_data").html(result);
});
}
});
});
Delete.php as
<?php
if(isset($_POST['data']))
{
$id_array = $_POST['data']; // return array
$id_count = count($_POST['data']); // count array
for($i=0; $i < $id_count; $i++)
{
$id = $id_array[$i];
$query = mysql_query("DELETE FROM `test` WHERE `id` = '$id'");
if(!$query)
{
die(mysql_error());
}
}?>
<tr>
<td>ID</td>
<td>TITLE</td>
<td>Select All <input type="checkbox" id="check_all" value=""></td>
</tr>
<?php
$query = mysql_query("SELECT * FROM `test`");
while($row = mysql_fetch_array($query))
{
?>
<tr>
<td>
<?php echo $row['id']; ?>
</td>
<td>
<?php echo $row['name']; ?>
</td>
<td>
<input type="checkbox" value="<?php echo $row['id'];?>" name="data[]" id="data">
</td>
</tr>
<?php
} unset($row);
}
I'm working with DataTables and CodeIgniter, and I've been working on exporting a table after filtering it by each column.
Since we're going to be using a lot of rows of data, I started working on the version where all of the processing (filtering, pagination, search, etc.) was based on the server. I'm currently having trouble exporting my filtered table into a PDF.
Issue that arise:
Only the rows that are currently visible to the user are exported for download. None of the other rows (especially those on other pages--separated through pagination) are included.
If the number of rows I get after filtering is > the number of rows allowed per page, I don't get all of the rows that I narrowed down my table to.
I would like some help as to how I would overcome this issue.
My code is as follows:
Views/List.php
<script>
$(document).ready( function () {
var oTable = $('#tablesupport').dataTable({
"sPaginationType":"bootstrap",
"oLanguage": {
"sSearch": "Search all columns:"
},
"sScrollY": "400px",
"bProcessing": true,
"bServerSide": true,
"sServerMethod": "GET",
"sAjaxSource": "dthelper",
"iDisplayLength": 10,
"aaSorting": [[0, 'asc']],
"aoColumns": [
{ "bVisible": true, "bSearchable": true, "bSortable": true },
{ "bVisible": true, "bSearchable": true, "bSortable": true },
{ "bVisible": true, "bSearchable": true, "bSortable": true },
{ "bVisible": true, "bSearchable": true, "bSortable": true },
{ "bVisible": true, "bSearchable": true, "bSortable": true },
{ "bVisible": true, "bSearchable": true, "bSortable": true }
]
});
//This function works completely fine if the table is processed client-side,
//I am not as successful on the server-side
function table2xls(oTable, exportmode, tableElm){
var xls = '';
var headers = [];
var rows = [];
xls +="<table><thead><tr>";
//Headers do not appear when server-side processing is used
$(tableElm+' thead').find('th').each(function() {
var $th = $(this);
var text = $th.text();
var header = '<th>' + text + '</th>';
// headers.push(header); // original code
if(text != "") headers.push(header);
});
xls += headers.join(" ");
xls += '<tbody><tr>';
// get table data
if (exportmode == "full") { // total data
var total = oTable.fnSettings().fnRecordsTotal();
for(i = 0; i < total; i++) {
var row = oTable.fnGetData(i);
row = strip_tags(row);
rows.push(row);
}
} else { // This branch works fine, however this does not work (in serv. side) for
// rows on other pages separated by pagination
var filteredrows = $("#tablesupport").dataTable()._('tr', {"filter": "applied"});
for ( var i = 0; i < filteredrows.length; i++ ) {
var numCols = 6;
var col = '<tr>';
for(var j = 0; j < numCols; j++){
if(j==2)
col+= '<td><div style="font-family: Mv Iyyu Formal;">' + filteredrows[i][j] + '</div></td>';
else
col += '<td>' + filteredrows[i][j] + '</td>';
}
//console.log(filteredrows[i][0]);
col += '</tr>';
rows.push(col);
};
/* $(tableElm+' tbody td:visible').each(function(index) {
var row = oTable.fnGetData(this);
row = strip_tags(row);
row = '<td>' + row + '</td>';
rows.push(row);
}); */
}
xls += rows.join();
xls += "</tr></tbody></table>";
//alert(xls);
$("#xlsinput").val(xls);
}
function strip_tags(html) {
var tmp = document.createElement("div");
tmp.innerHTML = html;
return tmp.textContent||tmp.innerText;
}
$("tfoot input").keyup( function () {
/* Filter on the column (the index) of this element */
oTable.fnFilter( this.value, $("tfoot input").index(this) );
} );
$.extend( $.fn.dataTableExt.oStdClasses, {
"sSortAsc": "header headerSortDown",
"sSortDesc": "header headerSortUp",
"sSortable": "header"
} );
$('#tablesupport tr').click(function() {
var href = $(this).find("a").attr("href");
if(href) {
window.location = href;
}
});
$('#export_visible_xls').click(function(event) {
event.preventDefault();
table2xls(oTable, 'visible', 'table#tablesupport');
});
} );
</script>
<div class="container">
<div class="row-fluid"><div class="span12">
<div class="span3">
<div class="btn-group" style="position:relative; right:170px;">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
Actions
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="#" id="export_visible" value="CSV" />CSV</a></li>
<li>PDF</li>
<li><a href="#" id="export_visible_xls" value="XLS" >XLS</a></li>
</ul>
</div>
</div>
<div id="down-button">
</div>
<div class="span3">
<form action=<?php echo base_url() . 'exports/toxls/member_export'; ?> method="post">
<input type="hidden" id="xlsinput" name="xlspost" />
<button type="submit" style="display: none; position: relative; right: 300px;" id="xlsdownload" name="submit" value="Download" class="btn btn-danger" > <i class="icon-download" ></i> Download</button>
</form>
</div>
<div class="span3">
<form action=<?php echo base_url() . 'exports/topdf'; ?> method="post">
<input type="hidden" id="pdfinput" name="pdfpost"></input>
<button type="submit" style="display: none; position: relative; right: 500px;" id="pdfdownload" name="submit" value="Download" class="btn btn-info"> <i class="icon-download" ></i> Download</button>
</form>
</div>
<div class="span3">
<form action=<?php echo base_url() . 'exports/tocsv/member_export'; ?> method="post">
<input type="hidden" id="csvinput" name="csvpost"/>
<button type="submit" style="display: none; position: relative; right: 710px" id="csvdownload" name="submit" value="Download" class="btn btn-primary"> <i class="icon-download" ></i> Download</button>
</form>
</div></div></div></div>
<div class="row-fluid">
<div class="span12">
<div class="span2"></div>
<div class="span8">
<div class="table-responsive">
<div id="dvData">
<table class = "table table-hover" id="tablesupport">
<thead>
<tr>
<th id='nid'>NID</th>
<th>Name (ENG)</th>
<th>Name (DV)</th>
<th>Current address</th>
<th>Permanent address</th>
<th>Status</th>
</tr>
</thead>
<tbody id="fbody" class="rowlink">
</tbody>
<tfoot>
<tr>
<th><input type="text" name="search_nid" placeholder="Search NID" class="search_init" /></th>
<th><input type="text" name="search_name" placeholder="Search Name (ENG)" class="search_init" /></th>
<th><input type="text" name="search_namedv" id="thaanaInput7" class="thaana" placeholder="ނަން ހޯދާ" class="search_init" /></th>
<th><input type="text" name="search_caddress" placeholder="Search curr. address" class="search_init" /></th>
<th><input type="text" name="search_paddress" placeholder="Search perm. address" class="search_init" /></th>
<th><input type="text" name="search_status" placeholder="Search status" class="search_init" /></th>
</tr>
</tfoot>
</table>
</div></div><div class="span2"></div></div></div>
Controllers/Record/dthelper() function
public function dthelper(){
$numCols = 6;
$this->load->database();
$aColumns = array('member_NID', 'member_fName', 'member_mName', 'member_lName', 'member_fNameDV', 'member_mNameDV', 'member_lNameDV',
'member_currAtoll', 'member_currIsland','member_currAddress', 'member_permAtoll', 'member_permIsland', 'member_permAddress', 'member_status');
$sTable = "membershiprecord";
$iDisplayStart = $this->input->get_post('iDisplayStart', true);
$iDisplayLength = $this->input->get_post('iDisplayLength', true);
$iSortCol_0 = $this->input->get_post('iSortCol_0', true);
$iSortingCols = $this->input->get_post('iSortingCols', true);
$sSearch = $this->input->get_post('sSearch', true);
$sSearch_0 = $this->input->get_post('sSearch_0', true);
$sSearch_1 = $this->input->get_post('sSearch_1', true);
$sSearch_2 = $this->input->get_post('sSearch_2', true);
$sSearch_3 = $this->input->get_post('sSearch_3', true);
$sSearch_4 = $this->input->get_post('sSearch_4', true);
$sEcho = $this->input->get_post('sEcho', true);
// Paging
if(isset($iDisplayStart) && $iDisplayLength != '-1')
{
$this->db->limit($this->db->escape_str($iDisplayLength), $this->db->escape_str($iDisplayStart));
}
// Ordering
if(isset($iSortCol_0))
{
for($i=0; $i<intval($iSortingCols); $i++)
{
$iSortCol = $this->input->get_post('iSortCol_'.$i, true);
$bSortable = $this->input->get_post('bSortable_'.intval($iSortCol), true);
$sSortDir = $this->input->get_post('sSortDir_'.$i, true);
if($bSortable == 'true')
{
$this->db->order_by($aColumns[intval($this->db->escape_str($iSortCol))], $this->db->escape_str($sSortDir));
}
}
}
/*
* Filtering
* NOTE this does not match the built-in DataTables filtering which does it
* word by word on any field. It's possible to do here, but concerned about efficiency
* on very large tables, and MySQL's regex functionality is very limited
*/
if(isset($sSearch) && !empty($sSearch))
{
for($i=0; $i<count($numCols); $i++)
{
$bSearchable = $this->input->get_post('bSearchable_'.$i, true);
// Individual column filtering
if(isset($bSearchable) && $bSearchable == 'true')
{
$this->db->like('member_NID', $this->db->escape_like_str($sSearch));
$this->db->or_like('member_fName', $this->db->escape_like_str($sSearch));
$this->db->or_like('member_mName', $this->db->escape_like_str($sSearch));
$this->db->or_like('member_lName', $this->db->escape_like_str($sSearch));
$this->db->or_like('member_fNameDV', $this->db->escape_like_str($sSearch));
$this->db->or_like('member_mNameDV', $this->db->escape_like_str($sSearch));
$this->db->or_like('member_lNameDV', $this->db->escape_like_str($sSearch));
$this->db->or_like('member_currAtoll', $this->db->escape_like_str($sSearch));
$this->db->or_like('member_currIsland', $this->db->escape_like_str($sSearch));
$this->db->or_like('member_currAddress', $this->db->escape_like_str($sSearch));
$this->db->or_like('member_permAtoll', $this->db->escape_like_str($sSearch));
$this->db->or_like('member_permIsland', $this->db->escape_like_str($sSearch));
$this->db->or_like('member_permAddress', $this->db->escape_like_str($sSearch));
$this->db->or_like('member_status', $this->db->escape_like_str($sSearch));
}
}
}
if(isset($sSearch_0) && !empty($sSearch_0))
{
$bSearchable = $this->input->get_post('bSearchable_0', true);
// Individual column filtering
if(isset($bSearchable) && $bSearchable == 'true')
{
$this->db->or_like('member_NID', $this->db->escape_like_str($sSearch_0));
}
}
if(isset($sSearch_1) && !empty($sSearch_1))
{
$bSearchable = $this->input->get_post('bSearchable_1', true);
// Individual column filtering
if(isset($bSearchable) && $bSearchable == 'true')
{
$this->db->like('member_fName', $this->db->escape_like_str($sSearch_1));
$this->db->or_like('member_mName', $this->db->escape_like_str($sSearch_1));
$this->db->or_like('member_lName', $this->db->escape_like_str($sSearch_1));
}
}
if(isset($sSearch_2) && !empty($sSearch_2))
{
$bSearchable = $this->input->get_post('bSearchable_2', true);
// Individual column filtering
if(isset($bSearchable) && $bSearchable == 'true')
{
$this->db->like('member_fNameDV', $this->db->escape_like_str($sSearch_2));
$this->db->or_like('member_mNameDV', $this->db->escape_like_str($sSearch_2));
$this->db->or_like('member_lNameDV', $this->db->escape_like_str($sSearch_2));
}
}
if(isset($sSearch_3) && !empty($sSearch_3))
{
$bSearchable = $this->input->get_post('bSearchable_3', true);
// Individual column filtering
if(isset($bSearchable) && $bSearchable == 'true')
{
$this->db->like('member_currAtoll', $this->db->escape_like_str($sSearch_3));
$this->db->or_like('member_currIsland', $this->db->escape_like_str($sSearch_3));
$this->db->or_like('member_currAddress', $this->db->escape_like_str($sSearch_3));
}
}
if(isset($sSearch_4) && !empty($sSearch_4))
{
$bSearchable = $this->input->get_post('bSearchable_4', true);
// Individual column filtering
if(isset($bSearchable) && $bSearchable == 'true')
{
$this->db->like('member_permAtoll', $this->db->escape_like_str($sSearch_4));
$this->db->or_like('member_permIsland', $this->db->escape_like_str($sSearch_4));
$this->db->or_like('member_permAddress', $this->db->escape_like_str($sSearch_4));
}
}
if(isset($sSearch_5) && !empty($sSearch_5))
{
$var = 0;
$bSearchable = $this->input->get_post('bSearchable_5', true);
// Individual column filtering
if(isset($bSearchable) && $bSearchable == 'true')
{
switch($sSearch_5){
case "Registered member":
$var = 1;
break;
case "Non-registered member":
$var = 2;
break;
case "Ex-member":
$var = 3;
break;
}
$this->db->like('member_status', $this->db->escape_like_str($var));
}
}
// Select Data
$this->db->select('SQL_CALC_FOUND_ROWS '.str_replace(' , ', ' ', implode(', ', $aColumns)), false);
$rResult = $this->db->get($sTable);
// Data set length after filtering
$this->db->select('FOUND_ROWS() AS found_rows');
$iFilteredTotal = $this->db->get()->row()->found_rows;
// Total data set length
$iTotal = $this->db->count_all($sTable);
// Output
$output = array(
'sEcho' => intval($sEcho),
'iTotalRecords' => $iTotal,
'iTotalDisplayRecords' => $iFilteredTotal,
'aaData' => array()
);
foreach($rResult->result_array() as $aRow)
{
$row = array();
/* foreach($aColumns as $col)
{
$row[] = $aRow[$col];
}*/
for($i=0; $i<sizeof($aColumns); $i++){
if($i == 1)
$row[] = $aRow[$aColumns[$i]] ." ". $aRow[$aColumns[$i+1]] ." ". $aRow[$aColumns[$i+2]];
else if($i == 4)
$row[] = $aRow[$aColumns[$i]] ." ". $aRow[$aColumns[$i+1]] ." ". $aRow[$aColumns[$i+2]];
else if($i == 7)
$row[] = $aRow[$aColumns[$i]] .", ". $aRow[$aColumns[$i+1]] .", ". $aRow[$aColumns[$i+2]];
else if($i == 10)
$row[] = $aRow[$aColumns[$i]] .", ". $aRow[$aColumns[$i+1]] .", ". $aRow[$aColumns[$i+2]];
else if($i==2 || $i == 3) continue;
else if($i ==5 || $i==6) continue;
else if($i ==8 || $i==9) continue;
else if($i ==11 || $i==12) continue;
else if($i==13){
$status = $aRow[$aColumns[$i]];
$var = '';
switch($status){
case "1":
$var = "Non-registered member";
break;
case "2":
$var = "Registered member";
break;
case "3":
$var = "Ex-member";
break;
}
$row[] = $var;
}
else $row[] = $aRow[$aColumns[$i]];
}
$output['aaData'][] = $row;
}
echo json_encode($output);
}
The ugliness of the above code has much to do with the fact that it was written in one sitting.
It's working.But has bug about searching muti value.
You should my function replace it.
//function searching by Jacker & Krucamper myreadyweb.com.
// Searching by Jacker & Kc.
if(!empty($sSearch))
{
$str_query = '';
$search_columns = array();
$total_searching = count($aColumns);
for($i=0; $i<$total_searching; $i++)
{
$bSearchable = $this->input->get_post('bSearchable_'.$i, true);
if(!empty($bSearchable))
{
$search_columns[$i] = array(
'columns' => $aColumns[$i],
'keyword' => addslashes($sSearch)
);
}
}
$total_search_column = count($search_columns);
if(!empty($search_columns))
{
foreach($search_columns as $key => $value)
{
if ($key != $total_search_column -1)
{
$str_query .= $value['columns']." REGEXP '".$value['keyword']."' OR ";
}
else
{
$str_query .= $value['columns']." REGEXP '".$value['keyword']."' ";
}
}
}
$str_query = "( $str_query )";
$this->db->where( $str_query, NULL, FALSE);
}
I need to display the selected sub-categories (multi) in the below div and also in some situations I need to close the div elements that are selected wrongly from the select box, so that I can add and delete elements to the div (by the above selectbox).
Even I made the similar code, but its not working for multi selection.
Briefly, I need the selected categories (multi) with close buttons in the below div.
<script type="text/javascript">
function selectlist() {
checkboxhome = document.getElementById("check");
catogery = document.getElementById("cat");
value = catogery.options[catogery.selectedIndex].value;
checkboxhome.innerHTML = "<br/> <p>" + value + "</p>";
}
</script>
<body>
<form action="#" enctype="multipart/form-data">
<select name="cat" id="cat" onchange="selectlist();" multiple="multiple">
<option>Select subcatogery</option>
<option value="fashion">Fashion</option>
<option value="jewelry">Jewelry</option>
<option value="dresses">dresses</option>
<option value="shirts">Shirts</option>
<option value="diamonds">Diamonds</option>
</select>
<div id="check">
</div></form>
</body>
</html>
Loop over the options and check if they are selected, something like this:
function selectlist() {
var checkboxhome = document.getElementById("check");
var category = document.getElementById("cat");
checkboxhome.innerHTML = '';
for (var i = 0; i < category.options.length; i++) {
if (category[i].selected) {
checkboxhome.innerHTML += "<p>" + category.options[i].value + "</p>";
}
}
}
Here is a fiddle of what could work for you: http://jsfiddle.net/maniator/W6gnX/
Javascript:
function selectlist() {
checkboxhome = document.getElementById("check");
catogery = document.getElementById("cat");
value = getMultiple(catogery);
checkboxhome.innerHTML = "<br/> <p>" + value + "</p>";
}
function getMultiple(ob)
{
var arSelected = new Array(), length = ob.length, i = 0, indexes = [];
while (ob.selectedIndex != -1 && i < length)
{
if (ob.selectedIndex != 0 && !in_array(ob.selectedIndex, indexes)) {
indexes.push(ob.selectedIndex)
arSelected.push(ob.options[ob.selectedIndex].value);
}
ob.options[ob.selectedIndex].selected = false;
i++;
}
var count = 0;
while(count < indexes.length){
ob.options[indexes[count]].selected = true;
count ++;
}
return arSelected;
}
function in_array(needle, haystack)
{
for(var key in haystack)
{
if(needle === haystack[key])
{
return true;
}
}
return false;
}