Hi,
After highlighting text, I would like to obtain the paragraph in which the selected text resides.
var select = window._content.document.getSelection();
Any pointers please?
I'm writing the JS for a chat appication I'm working on in my free time, and I need to have HTML identifiers that change according to user submitted data. This is usually something conceptually shaky enough that I would not even attempt it, but I don't see myself having much of a choice this time. What I need to do then is to escape the HTML id to make sure it won't allow for XSS or breaking HTML.
Here's the code:
var user_id = escape(id)
var txt = '<div class="chut">'+
'<div class="log" id="chut_'+user_id+'"></div>'+
'<textarea id="chut_'+user_id+'_msg"></textarea>'+
'<label for="chut_'+user_id+'_to">To:</label>'+
'<input type="text" id="chut_'+user_id+'_to" value='+user_id+' readonly="readonly" />'+
'<input type="submit" id="chut_'+user_id+'_send" value="Message"/>'+
'</div>';
What would be the best way to escape id to avoid any kind of problem mentioned above? As you can see, right now I'm using the built-in escape() function, but I'm not sure of how good this is supposed to be compared to other alternatives. I'm mostly used to sanitizing input before it goes in a text node, not an id itself.
Global.alert("base: " + base + ", upfront: " + upfront + ", both: " + (base + upfront));
This code above outputs this:
base: 15000, upfront: 36, both: 1500036
Why is it joining the two numbers instead of adding them up?
I eventually want to set the value of another field to this amount using this:
mainPanel.feesPanel.initialLoanAmount.setValue(Ext.util.Format.number((base + upfront), '$0,000.00'));
...and when I try that now it turns the number into the millions instead of 15,036.00. I have no idea why. Any ideas?
I have this small function that's behaving oddly to me. Easy enough to work around, but enough to pique my curiosity.
function formatNumber(number,style) {
if (typeof style == 'number') {
style = style.toString();
}
return (number).format(style);
}
The return format part is based on another function that requires the style variable to be a string to work properly, so I'm just checking if style is a number and if it is to convert it to a string. When the function above is written as is, the format function format doesn't work properly. However when I write it as simply:
return (number).format(style.toString());
Everything works. Is there a difference between putting the .toString function inside the format call vs performing it before hand and setting it as the variable style?
Hi, I am using this code to refresh the data inside of the div:
<script>
$(function() {
$("#refresh").click(function() {
$("#new").load("/new.php")
})
})
</script>
Except it loads the who page inside of the div, instead of just the information that is inside of the div.
How do I make it refresh only the data that is inside of the div? Is there a way of doing it other than putting the information for that div in a seperate page?
I have a table with 5 rows and 2 columns. Each cell contains a text box. I want to show error if one of the text boxes in each column is empty. I want both text boxes in a row shld be filled or both shld empty.
How can i do this via Asp.net validation controls?
function SimpleSymbols(str) {
var letter =['a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
var newstr = "";
for (var i = 0; i<str.length; i++){
if (str.charAt(i).toLowerCase() in letter){
newstr += "M";
}
else{
newstr += "X";
}
}
return newstr;
}
If str is "Argument goes here" it returns XXXXXXXXX. WHy doesn't it return MMMMMMMMMM?
I have classes looks like below:
function Student(name, surname, lossons){
this.Name = name;
this.Surname = surname;
this.Lessons = lessons;
}
function Lesson(){
this.Name = name;
this.studentCount = count;
}
And i want to write ToString method to them. But i don't want to write and add them one by one. Is there any way to do this like reflection in C# or Java ?
Any help would be appreciated...
Hello,
My string contain a lot of HTML entities, like this
"Hello <everybody>" there
And I want to split it by HTML entities into this :
Hello
everybody
there
Can anybody suggest me a way to do this please? May be using Regex? Thanks so much.
Hi,
I have the following code. I expected to see "archive" object on my firebug console, but I see Window object. Is it normal?
var archive = function(){}
archive.prototype.action = {
test: function(callback){
callback();
},
test2: function(){
console.log(this);
}
}
var oArchive = new archive();
oArchive.action.test(oArchive.action.test2);
Hello, i am trying to bind an event to a dynamically created div.
function GameField(playerNumber) {
this.fields = new Array();
this.player = playerNumber;
this.isPlayerActive = false;
this.currentRound = 0;
}
GameField.prototype.InitField = function(fieldNumber) {
var newField = document.createElement("div");
if (fieldNumber == 0 || fieldNumber == 6 || fieldNumber == 8 || fieldNumber == 17)
newField.className = 'gameCellSmall borderFull gameText gameTextAlign';
else
newField.className = 'gameCellSmall borderWithoutTop gameText gameTextAlign';
newField.onclick = function() { this.DivClick('a'); }
this.fields[fieldNumber] = newField;
return newField;
}
GameField.prototype.DivClick = function(fieldNumber) {
alert('Nummer: ' + fieldNumber);
}
Everything works perfectly, but when you click on one of the created divs, i end up with the following error message: Error: Object doesn't support this property or method.
If i replace the onclick function with this, then it works:
newField.onclick = function() { alert('Nummer: ' + fieldNumber); }
How can i get the onclick event to fire my DivClick function instead?
Here is my function:
function processCheck() {
var numberClicked = 0;
var frm = document.getElementById('form');
for (var i=0; i<form.elements.length; i++) {
if (frm.elements[i].checked)
numberClicked++;
}
if(numberClicked != 8)
alert('Must choose 8 Teams');
else
frm.submit();
}
My forms name is 'form', here is my input:
echo "<input type='button' name='submit' value='Update' onclick='processCheck()' />";
When i click the button and there is anything but 8 boxes selected it displays the alert, if there is 8 boxes it does nothing (<-- The problem). I have the form action set to another page.
sometimes we loss the new keyword when define new object,
obj = new Clazz(); //correct
obj = Clazz(); //wrong, but no syntax error, hard to debug.
I want to write a function to help me create Class and make it new safe.
var Class = function(constructor){
//when constructor
// if not call by new
return new constructor();
// else
constructor();
}
var MyClazz = Class(function(name){
this.name = name
}, SuperClazz1, SuperClass2 )
MyClazz.extend({
show: function(){console.log(this.name)}
})
obj1 = new MyClazz();
obj2 = MyClazz();
// obj1 should same as obj2
Is it possible, any exists module?
Hi All,
Is there a way in any browser to add/remove class names? For example, if I have a div with class names and I just want to remove/add 'name2' is there a way to do that?
Thanks,
rodchar
I have this code:
document.getElementById('root').style.left = '<?php echo $page_position[$info["os"]][$info["browser"]][0]; ?>';
document.getElementById('root').style.top = '<?php echo $page_position[$info["os"]][$info["browser"]][1]; ?>';
Why won't this work like this?
Can anybody point me in the right direction?
EDIT:
<?php echo $page_position[$info["os"]][$info["browser"]][1]; ?>
echoed "top:300px;"
Sorry guys, very stupid error of mine :/
Is it possible to get the source of the current HTML document, exactly as it was loaded, in text form? (i.e. not the "Generated source" after parsing and DOM manipulation.)
Note: Issuing an extra AJAX request to retrieve the HTML page again is not an option in this case: The document could have changed.
How do I retrieve the month from the current date in mm format? (i.e. "05")
This is my current code:
var currentDate = new Date();
var currentMonth = currentDate.getMonth() + 1;
I was trying to remove some items from an array ,
Array.prototype.remove = function(from, to)
{
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
var BOM = [0,1,0,1,0,1,1];
var bomlength = BOM.length;
for(var i = 0; i < IDLEN ;++i)
{
if( BOM[i] == 1)
{
BOM.remove(i);
//IDLEN--;
}
}
RESULT IS
BOM = [0,0,0,1];
expected result is
BOM = [0,0,0];
its looks like i am doing something wrong , Please help me.
Thanks.
Hello
So i have this:
yes: <input type="radio" value="Y" id="SCvoteY" name="vote"></input> no: <input type="radio" id="SCvoteN" value="N" name="vote"> </input>
How do i write that it should transfer name="vote" data ? #vote doesnt work, .vote either (guess it cause thats for class and ID) but what about name then?
function DoSCInsert(){
$("#SCres").html("please wait..");
var nocache = '0';
var data = { fID : $("#fID").val(), vote : $("#vote").val(), comment: $("#comment").val(), nocache: nocache };
$.get('insertSC.php', data, onSCInsertComplete);
}
And how do i shorten this, ive heard that you can you a function in jquery called serialize to pass strings but can you(if you know how) show example by this script how to pass it like this one does?
I'm thinking whether it makes sense in order to increase the speed of the website to do some strategy of caching the js files that are being included ?
one idea that I have is to do something like this:
[OutputCache(Location = OutputCacheLocation.Any, Duration = 3600)]
public JsController : Controller
public ActionResult JQuery()
{
//I would have a ascx with the entire jquery script inside
return View();
}
and on the site.master:
<%=Html.RenderAction("JQuery","JsController");
var exampleURL = '/example/url/345234/test/';
var numbersOnly = [?]
The /url/ and /test portions of the path will always be the same.
Note that I need the numbers between /url/ and /test. In the example URL above, the placeholder word example might be numbers too from time to time but in that case it shouldn't be matched. Only the numbers between /url/ and /test.
Thanks!
The following code works:
$(".valClear").each(function () {
if ($(this).val().indexOf(".png") == -1) {
$(this).val('');
}
});
However this doesn't (the value is removed even if it contains .png or .jpeg), what am I doing wrong?
$(".valClear").each(function () {
if (($(this).val().indexOf(".png") == -1) || ($(this).val().indexOf(".jpeg") == -1)) {
$(this).val('');
}
});
This seems to work on everything but explorer:
NextButJar.addEvent("click", function() {
if (this.disabled == true) {
alert("Please view all tabs first!");
return;
}
});
Any help welcome