I don't want my website's user to use backspace to go to the previous page,
but I still want to keep the use of backspace,
just like deleting wrong typing.
How can I do?
Thanks a lot.
I have two click-events, that are nearly similar, but not quite. I am wondering how to refactor them best:
$('.remove_fields.dynamic').live('click', function(e) {
var $this = $(this);
var after_removal_trigger_node = $this.closest(".nested-fields").parent();
trigger_removal_callback($this);
e.preventDefault();
$this.closest(".nested-fields").remove();
trigger_after_removal_callback(after_removal_trigger_node);
});
$('.remove_fields.existing').live('click', function(e) {
var $this = $(this);
var after_removal_trigger_node = $this.closest(".nested-fields").parent();
trigger_removal_callback($this);
e.preventDefault();
$this.prev("input[type=hidden]").val("1");
$this.closest(".nested-fields").hide();
trigger_after_removal_callback(after_removal_trigger_node);
});
As you can tell there is a fair bit of overlap. I am wondering what the best/nicest way would be to refactor this code.
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
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.
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;
}
}
}
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
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 />
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", ....
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
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!
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 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.
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
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?
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
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 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?
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 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
HI volks,
I try to set some hidden form field values with an onclick event.
Ok, after I did something like this:
document.getElementById('hidden_field').value = 123;
I can output the value with the firebug console by entering this:
alert(document.getElementById('hidden_field').value);
So the values are definitely set. But now when I submit the form, the hidden field values are still empty.
Do you have any idea whats going wrong?
Thx for your answers.
I'm currently coding counter system and have spotted one problem with flash banners without wmode attribute at all, loaded via iframe from another website.
Works only mouseout event.
The problem is, that i can't catch click event on those banners.
Is there any solution?
Thanks.