How can I match the following pattern?
"anything123.anythingelse"
Alphanum of any length, with exactly 1 "." in the middle, and then alphanum of any length?
Thanks.
Can someone who is a master at JS tell me what's wrong with this?
if ( $.trim($("#add-box-text").val()).length < 2 && $.trim($("#add-box-text").val()) != "Click here to add an item" ) {
// If it's LT than 1 Character, don't submit
$("#add-box-text").effect('highlight', {color: '#BDC1C7'}, 500);
// Refocus
$("#add-box-text").focus();
}
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
Hi ,
taken accordian menu in some open source site,
my accordian url
But i want to change this static width to dynamic ,
That is height need to change as AUTO for inside accordian view...
Hi how should i iterate array of variables and reassign value to each variable. E.g in jQuery
function test(param1, param2) {
$.each([param1, param2], function (i, v) {
//check if all the input params have value, else assign the default value to it
if (!v)
v = default_value; //this is wrong, can't use v, which is value
}
}
How should I get the variable and assign new value in the loop?
Thank you very much!
I have a string that looks like "(3) New stuff" where 3 can be any number.
I would like to add or subtract to this number.
I figured out the following way:
var thenumber = string.match((/\d+/));
thenumber++;
string = string.replace(/\(\d+\)/ ,'('+ thenumber +')');
Is there a more elegant way to do it?
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?
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.
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.
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);
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?
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?
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?
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...
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;
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.
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 :/
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.