I want this type of functionality in my project.
Here is the JS Bin link.
There are 3 files stylesheet.css, javascript.js and a html file.
I'm trying in Visual Studio 2010 ASP.NET C# but it is not working: the Javascript file is not loaded.
ASPX code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link rel="stylesheet" href="StyleSheet.css" type="text/css" />
<script type="text/javascript" src="JScript.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div id="editor" contenteditable="true"></div>
</form>
</body>
</html>
StyleSheet.css:
body {
}
#editor {
width: 400px;
height: 100px;
padding: 10px;
background-color: #444;
color: white;
font-size: 14px;
font-family: monospace;
display:block;
}
.statement {
color: orange;
}
JScript.js:
$("#editor").on("keydown keyup", function (e) {
if (e.keyCode == 32) {
var text = $(this).text().replace(/[\s]+/g, " ").trim();
var word = text.split(" ");
var newHTML = "";
$.each(word, function (index, value) {
switch (value.toUpperCase()) {
case "SELECT":
case "FROM":
case "WHERE":
case "LIKE":
case "BETWEEN":
case "NOT LIKE":
case "FALSE":
case "NULL":
case "FROM":
case "TRUE":
case "NOT IN":
newHTML += "<span class='statement'>" + value + " </span>";
break;
default:
newHTML += "<span class='other'>" + value + " </span>";
}
});
$(this).html(newHTML);
//// Set cursor postion to end of text
var child = $(this).children();
var range = document.createRange();
var sel = window.getSelection();
range.setStart(child[child.length - 1], 1);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
$(this)[0].focus();
}
});
JScript.js file is not working. Keyword color not changing but i provided the link its working fine.
How can i resolve this issue?
$which means this file needsjQueryor subsets. Load themjQuerybefore using it...jQuerylibrary that you're trying to use.