How to set multiple value in selectize input? - javascript

I try some solution but didn't work
<input id="select1" name="select1" type="text" class="select1 demo-default"/>
var $select = $("#select1").selectize();
var selectize = $select[0].selectize;
selectize.setValue(["test1","test2"]);`

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Selectize</title>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.6/css/selectize.default.min.css">
</head>
<body>
<div id="wrapper">
<input type="text" id="input-tags1" class="demo-default test">
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.6/js/standalone/selectize.js"></script>
<script>
var $select = $('.demo-default').selectize({
persist: false,
createOnBlur: true,
create: true,
});
var selectize = $select[0].selectize;
selectize.addOption([{text: "puja", value: "puja"}, {text: "raxit", value: "raxit"},]);
selectize.setValue(['puja','raxit']);
</script>
</body>
</html>

Related

Equations are not being formatted when I append new equation MathJax

I am facing a problem using mathjax. the equations already available are formatted but the equations that I put by myself are not being formatted.
here is my code:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script async="true" src="https://cdn.jsdelivr.net/npm/mathjax#2/MathJax.js?config=AM_CHTML">
</script>
</head>
<body>
<input type="text" id="eq">
<button onclick="amb()">equation</button>
<p id="amb"></p>
<p>`x^3`</p>
<script>
function amb() {
eq = document.getElementById('eq').value;
document.getElementById('amb').append("`" + eq + "`");
}
</script>
</body>
</html>
First, I suggest use a form and a type=submit button for a better UX.
I found the solution you need to queue an action to rescan the page: MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script async="true" src="https://cdn.jsdelivr.net/npm/mathjax#2/MathJax.js?config=AM_CHTML">
</script>
</head>
<body>
<form onsubmit="amb(); return false">
<input type="text" id="eq">
<input type="submit" value="equation">
</form>
<p id="amb"></p>
<p>`x^3`</p>
<script>
function amb() {
eq = document.getElementById('eq').value;
document.getElementById('amb').innerText = ("`" + eq + "`");
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
</script>
</body>
</html>

Why isn't Select2 being applied to my select element?

This is the input I want to add my project https://select2.org/tagging but it's show like this:
I added Select2 installation links but it doesn't work. What am I doing wrong?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/select2#4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2#4.1.0-rc.0/dist/js/select2.min.js"></script>
<title>Document</title>
</head>
<body>
<select class="form-control">
<option selected="selected">orange</option>
<option>white</option>
<option>purple</option>
</select>
<script>
$(".js-example-tags").select2({
tags: true
});
</script>
</body>
</html>
The class name in your script doesn't occur in your markup. It needs to be on the select element.
Also, you don't seem to be loading jQuery, on which Select2 depends.
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/select2#4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2#4.1.0-rc.0/dist/js/select2.min.js"></script>
</head>
<body>
<select class="form-control js-example-tags">
<option selected="selected">orange</option>
<option>white</option>
<option>purple</option>
</select>
<script>
$(".js-example-tags").select2({
tags: true
});
</script>
</body>

Jquery UI resizable not working on empty contentedible

I try to initialize the jquery ui resizable on a contenteditable div, but then I cannot edit the empty div content
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div style="width: 100%; height: 100px;" contenteditable=true></div>
<script>
$('div').resizable()
</script>
</body>
</html>
https://jsbin.com/wakowes
Add a tag to the empty div and then it will work
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div style="width: 100%; height: 100px;" contenteditable=true> </div>
<script>
$('div').resizable()
</script>
</body>
</html>
https://jsbin.com/dulelox

how to unable kendo grid checkbox?

In the code snippet is the example of grid, I would like to unable the checkbox in the grid when the remark have invalid value. In the code below will have 3 sample records.
Output:
The first and third checkbox set to unable, the second checkbox are enable to let user to select.
var userRecord=[{reason:"Invalid",UserName:"test"},
{reason:"",UserName:"test1"},
{reason:"Invalid2",UserName:"test2"}]
var grid=$("#grid").kendoGrid({
columns: [
{ field: "", width: "40px", template: "<input name='Discontinued' class='checkbox' type='checkbox' />" },
{ field: "reason", title: "Remark" },
{ field: "UserName", title: "User Name" },
],
dataSource: {
data: userRecord
},
dataBound: function (e) {
$(".checkbox").bind("change", function (e) {
var grid = $("#grid").data("kendoGrid");
var row = $(e.target).closest("tr");
row.toggleClass("k-state-selected");
var data = grid.dataItem(row);
});
}
});
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.914/styles/kendo.common-bootstrap.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.914/styles/kendo.bootstrap.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.914/styles/kendo.bootstrap.mobile.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.3.914/js/kendo.all.min.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.2.607/js/kendo.all.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div id="grid"></div>
</body>
</html>
Try something like this: #= (reason=='')? 'disabled=disabled' : ''#
I am not sure if you want first and third disabled or you want the middle one disabled but I think you got the idea.
var userRecord=[{reason:"Invalid",UserName:"test"},
{reason:"",UserName:"test1"},
{reason:"Invalid2",UserName:"test2"}]
var grid=$("#grid").kendoGrid({
columns: [
{ field: "", width: "40px", template: "<input name='Discontinued' class='checkbox' #= (reason=='')? 'disabled=disabled' : ''# type='checkbox' />" },
{ field: "reason", title: "Remark" },
{ field: "UserName", title: "User Name" },
],
dataSource: {
data: userRecord
},
dataBound: function (e) {
$(".checkbox").bind("change", function (e) {
var grid = $("#grid").data("kendoGrid");
var row = $(e.target).closest("tr");
row.toggleClass("k-state-selected");
var data = grid.dataItem(row);
});
}
});
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.914/styles/kendo.common-bootstrap.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.914/styles/kendo.bootstrap.min.css" />
<link rel="stylesheet" href="//kendo.cdn.telerik.com/2016.3.914/styles/kendo.bootstrap.mobile.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.3.914/js/kendo.all.min.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://kendo.cdn.telerik.com/2016.2.607/js/kendo.all.min.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div id="grid"></div>
</body>
</html>

JQuery keyup/down isn't working in chrome

$('#user_text').keyup(function(){
var user_text = $('#user_text').val();
$('#user_text_feedback').html(user_text);
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jquery</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<input type="text" id="user_text" value="hey"><br />
<span id="user_text_feedback"></span>
</body>
</html>
I'm using google chrome as my default browser. I tried to execute the above code but I'm not getting the required output.I also tried using keydown instead of keyup I wasn't getting the proper output
Change $('#user_link') to $('#user_text'):
$('#user_text').keyup(function(){
var user_text = $('#user_text').val();
$('#user_text_feedback').html(user_text);
});
Working here you should use #user_text :
$('#user_text').keyup(function(){
var user_text = $('#user_text').val();
$('#user_text_feedback').html(user_text);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jquery</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<input type="text" id="user_text" value="hey"><br />
<span id="user_text_feedback"></span>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/init.js"></script>
</body>
</html>

Categories