I would like to match a digit and replace it with that many spaces. Can this be done in less than 9 lines of code?
Example
"asnthsnth4nts4h3n" --> "asnthsnth nts h n"
i have a string like following:
Assigned to ram on 2010-04-22 12:30:13.0
i need to extract the third word (ram). I tried the below regex, its not working.
/\s[a-zA-Z]*\s/
any help to fix this would be greatly appreciated.
I'm sure this is really simple, but I need some help.
I'm trying to insert a variable into an anchor in the following snippet
var tablerows = ''
$.each( data, function(index,row){
id = row.shift()
tablerows += '<tr><td><a href="getuserimage.php?id=" target="_blank">' + row.shift() + '</a></td>'
tablerows += '<td>' + row.join('</td><td>') + '</td></tr>'
})
$("#users-table > tbody").html(tablerows)
I'm just not sure how to get the id in there
Hi,
Have a bubblesort routine similar the this. I need to make it more efficient by stopping the loop when the array is sorted or if the array is already sorted.
function sortNumbers(listbox) {
var x, y, holder;
// The Bubble Sort method.
for(x = 0; x < ranarray.length; x++) {
for(y = 0; y < (ranarray.length-1); y++) {
if(ranarray[y] > ranarray[y+1]) {
holder = ranarray[y+1];
ranarray[y+1] = ranarray[y];
ranarray[y] = holder;
}
}
}
var user = {};
now I want to create a setUsers method that takes a key/value pair object and initializes the user variable.
setUsers = function(data) {
// loop and init user
}
where data is like:
234: "john", 23421: "smith", ....
Hi, so I know there are tons of ways to simulate inheritance and other OO features. I have chosen one to use for my project and am wondering if I can create an instance and add stuff to it and keep it contained (within braces).
Consider the following:
function BaseClass(){
<this.stuff here>
}
function SubClass(){
this.superClass = BaseClass();
this.superClass();
<this.other stuff here>
}
myObj = new SubClass();
so myObj is an instance of SubClass. I can add things to myObj like:
myObj.blah = "funtimes";
What I would like is to be able to add stuff to the "instance" and keep it organized in braces much like the constructor. psuedo code like:
myObj = new SubClass() {
var blah = "funtimes"
<more instance specific stuff here>
}
Is something like this possible?
Thanks!
hello friends sorry for previous question actuly my question is i am having one button called btn[0] which is allready on browser when it is loaded when i click on btn[0] it will create another button element called btn[1] now btn[0]'s click event is disabled and when i click on btn[1] it will also generate another button which called btn[2] when i click on btn[2] it will generate another btn called btn[3] and so on
I am planning to build a JS based twitter client. Information about libraries/clients is pretty old on other SO Questions. I was wondering if anyone has come across wrappers other than Spaz and TwitterHelper.
Thanks :-)
I'm having a bit of an issue with me code. I'm trying to do a calculation from a drop down menu and then it will onChange to a textbox. I've been at it for days trying to figure it out and Googling ways to code the function. Can anyone please help or give me advice on how to approach this?
function numGuest()
{
var a = document.getElementById("guests");
if(a.options[a.selectedIndex].value == "0")
{
registration.banq.value = "0";
}
else if(a.options[a.selectedIndex].value == "1")
{
registration.banq.value = "30";
}
}
<select id="guests" name="guests">
<option value="0">0</option>
<option value="1">1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<input type="text" id="banq" name="banq" onChange="numGuest()" disabled />
I'm in the process of designing this site http://www.parisgaa.org/parisgaels and have a problem.
The image slider on the homepage messes up sometimes. Most of the time it works and looks fine, but other times its positioning seems to get messed up and it appears underneath the content that should be below it (i.e. with that content overlapping the image). You should be able to replicate this in Chrome - just refresh a couple of times.
I'd appreciate any help at all.
Title says it all. I know this can be done in IE by creating an ActiveX object, but how do I do it in FF. The navigator.plugins['Adobe Acrobat'] object lets me know if it's installed or not, but it doesn't contain the version number. Any ideas?
I'm experiencing a problem of $.get function.
The url contains JSON
this is my code:
xyz = null
$.get('http://www.someurl.com/123=json', function(data) {
var xyz = data.positions[0].latitude;
});
alert(xyz);
//some more code using xyz variable
I know that xyz will alert a null result because the $.get is asychronous.
So is there any way I can use the xyz outside this get function?
Thank you
Hi guys,
Had a look and found some things on this, but nothing seems to work as I'd like it.
Initially I had my solution working with internet explorer and chrome, but not firefox (which is unsatisfactory for me to not have working)
What I'm looking for is a simple text area, which sends data on enter key, but creates a new line on Shift+Enter. The following is what I have
function goReturn(e,str) {
var e = (window.Event) ? e.which : e.keyCode;
if (e.shiftKey && e=="13") {
document.getElementById("wall").value =
document.getElementById("wall").value+"\n";
} else if(e=="13"){
// ...continue to send data
}
}
This sends the data on enter, but also sends the data on shift and enter (which is the problem I have).
Thanks for any assistance
I need to access to a value in a checkbox, the atribute value has content, so i need to place the id somewhere else i created a label, but i have not access to that value
alert(check[i].label); // doesnt work
where else can i place a value in checkbox.
Please dont write that i can do this
<input type='checkbox' id='bla' name='mybla' vlaue='myvalue'> Hy
Where can i place some other values ?
I tryed with this
<input type='checkbox' id='bla' name='mybla' vlaue='myvalue' label='myothervalue'> Hy
first i get all checkbox ect... and in the for loop i did this
alert(check[i].label); // doesnt work
How can i do that?
I've tried some HTML DOM code from several sites, but it isn't working. It isn't adding anything. Does anyone have a working example on this?
this.img = document.createElement("img");
this.img.src = "img/eqp/"+this.apparel+"/"+this.facing+"_idle.png";
src = getElementById("gamediv");
src.appendChild(this.img)
But it isn't adding anything to the div. (gamediv) I've tried document.body as well, with no result.
Thanks in advance.
Hello everybody,
I just have a quick question about how to generate id's on-the-fly for HTML elements.
So far I've tried a few things, I started with a "for" loop, I already know how many elements I have to generate Id's for, in this case I have an "ul" with 6 "li".
My "for" loop is as follows:
var items = $("ul li").length;
for(var i = 0; i <= items; i++){
$("ul li").attr("id", "number" + i);
}
"number" would be the new id concatenated with "i", so I get a different Id for each "li".
As you can probably tell, this does not work, because I end up with the same Id for each "li":
in this case I get <li id="number6">... </li> for all the "li" elments in the "ul".
I tried a "while" loop and ".each()" with jQuery but I get the exact same thing.
Any help would be appreciated.
parseInt("7em", 10); returns 7 in all browsers I tested [*]. But can I rely on this?
The reason I ask is, that I want to perform some calculations based on em, like
/* elem1.style.top uses em units */
elem2.style.top = parseInt(elem1.style.top, 10) + 1 + "em";
I could do this with regular expressions, but parseInt is easier to use, and probably a bit faster. Or is there another solution (maybe using jQuery)?
[*] Tested so far on: IE 6, IE 8, Safari 4, Firefox 3.6, Opera 10.5
$(document).ready(function(){
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var month = new array("January","February","March","April","May","June","July","August","September","October","November","December");
var mon;
mon = month(m);
var today = m+"/"+d+"/"+y
$('#calendar').append('<div id="today">Today is'+' '+mon+'/'+d+'/'+y+'.');
});
Is there a way to figure out what the top domain for the hostname of the current page is? The problem I have is that the script could be on .com domain, or in an international domain like .co.uk
So for:
jobs.telegraph.co.uk - top domain is:telegraph.co.uk
jobs.nytimes.com - top domain is nytimes.com
The problem is that location.hostname , and the document.domain give the entire domain.
One route is to have a list of all TLDs (too much to carry around) and parse based on that. Another route was if 2 characters after last ".", than internationaltion - hence last two are the TLD, but that does not hold true for all international domains.
I've come across this.inheritFrom that enables you to inherit from a super class.
var superClass = function() {
this.foo = 'foo';
this.bar = 'bar';
}
var subClass = function() {
this.inheritFrom = superClass;
this.inheritFrom();
this.myFunction = function() {
return this.foo;
};
}
I've looked in Mozilla and MSDN, but I can't seem to find it documented any where. As far as I can see it works in IE6 and Firefox 3. Any reason why it wouldn't be documented?
hello friends sorry for previous question actuly my question is i am having one button called btn[0] which is allready on browser when it is loaded when i click on btn[0] it will create another button element called btn[1] now btn[0]'s click event is disabled and when i click on btn[1] it will also generate another button which called btn[2] when i click on btn[2] it will generate another btn called btn[3] and so on