I can round to x amount of decimal places with math.round but is there a way to round left of the decimal? for example 5 becomes 05 if I specify 2 places
Sorter.prototype.init_bubblesort = function(){
console.log(this.rect_array);
this.end = this.rect_array.length;
this.bubblesort();
}
Sorter.prototype.init = function(array,sort_type){
this.rect_array = array;
this.init_bubblesort();
}
The code above works as expected, but when I change the init function to:
Sorter.prototype.init = function(array,sort_type){
var sort_types = {'bubblesort':this.init_bubblesort,
'quicksort':this.init_quicksort,
'liamsort':this.init_liamsort};
this.rect_array = array;
sort_types[sort_type]();
}
the init_bubblesort function results in an error saying this.rect_array is undefined. I'm trying to wrap my head around why init_bubblesort no longer as access to it's instance's variables.
How can the scrollbar be hidden? I want to do this because the scrollbar is not nice.
overflow:hidden is not useful, because my div element has many other elements.
So setting overflow does not solve my problem.
I'm trying to write a function that needs to know the property names of an object being passed in, like so:
var data = { "key1":"value1", "key2":"value2", etc}
^ i want the string value "key1"
How do I retrieve the string "key1" from data? I know I can set a property dynamically like data[prop]=value but i want to know what prop is from an object passed in.
If that doesn't make sense I suppose I could try to explain more. Thanks!
I eventually want to do something like:
for (var i = 0; i<data.length; i++)
{
var name = data[i].getPropertyName() <--- not a real function
// do stuff
}
Is it possible to read/edit iframe contents(not only properties like src) with scripts that are on page but outside of this frame? I know that is impossible if source is from other site as it would be a big serurity hole, but I only ask whether it works for other content from the same origin.
i have a textbox in asp.net form.... if i entered numbers not like 7 or 8 or 9, then script function should be araised with alert message.... how to achieve this.... that 7 or 8 or 9 are first digits in my texbox...
Hi,
I wanted to know how I could find the previous active control on a page. I have a couple of textboxes and a button, and when i am on a certain textbox and I click the button, I want to highlight that textbox. I have the highlight functionality covered, but I don't know how to find out which textbox to run the function on...
Please help,
Thanks!
I have a html page with a timer in it. I'm starting the timer with the keypress event, but i want it to execute only for the first key. I'm using a variable to catch the total keys in an other function which there were pressed and i have something like that: if(totaAttempts==1) start the timer, but with this solution the timer starts correctly, but is stomps when a key is pressed again. Any better ideas?
Thanks in advance
function setTime() {
if (totalAttempts == 1) {
++totalSeconds;
secondsLabel.innerHTML = pad(totalSeconds % 60);
minutesLabel.innerHTML = pad(parseInt(totalSeconds / 60));
}
}
function pad(val) {
var valString = val + "";
if (valString.length < 2) {
return "0" + valString;
} else {
return valString;
}
}
I'm rubbish at Regular Expressions, really!
What I'd like is to split a string containing a CCS property value into an array of [string,value,unit].
For example: if I supplied the .split() method with 1px it'd return ["1px",1,"px"]. If I were to supply, similarly, 10% it'd return ["10%",10,"%"].
Can this be done?
I appreciate all your help!
Greetings,
The question relates to ASP.NET MVC
I am creating some divs dynamically using AJAX (some views render dynamically). Inside these views a have some JS code. When user click on link i would like to open dialog box with google map. However, because these views are rendered dynamically it does not work because js code is not injected (what can be seen in page source). How can I resolve this problem?
Hey guys,
I want to create a form which has a text entry box where a user can enter their name and then I want a button as well. But what I want this button to have a function called ReadName() where what will happen is when the user clicks on the button it will come up with a message saying "Hello user name will appear here
I have tried my self and but I don't think I am not getting what I want. Any help will be appreciated.
<form>
<label for="name">Name:/label>
<input type="text" name="name" id="name"/>
<input type="text" name="name" onfocus="ReadName()"/>
</form>
I have a full path to an image, which I am using jquery to read, in the form $('img.my_image').attr('src') however I just want the filename portion (discarding the path).
Are there any built-in functions to do this, or would a regex be the only option?
I have a version number with 3 digits as a String,
var version = "1.2.3";
and would like to compare it to another version. To see if version is newer than otherversion,
var otherVersion = "1.2.4";
How would you do it?
I am having some trouble getting a callback function to work. Here is my code:
SomeObject.prototype.refreshData = function()
{
var read_obj = new SomeAjaxCall("read_some_data", { }, this.readSuccess, this.readFail);
}
SomeObject.prototype.readSuccess = function(response)
{
this.data = response;
this.someList = [];
for (var i = 0; i < this.data.length; i++)
{
var systemData = this.data[i];
var system = new SomeSystem(systemData);
this.someList.push(system);
}
this.refreshList();
}
Basically SomeAjaxCall is making an ajax request for data. If it works we use the callback 'this.readSuccess' and if it fails 'this.readFail'.
I have figured out that 'this' in the SomeObject.readSuccess is the global this (aka the window object) because my callbacks are being called as functions and not member methods. My understanding is that I need to use closures to keep the 'this' around, however, I have not been able to get this to work.
If someone is able show me what I should be doing I would appreciate it greatly. I am still wrapping my head around how closures work and specifically how they would work in this situation.
Thanks!
Given the following string:
var str = "one,two,three";
If I split the string on the commas, I normally get an array, as expected:
var arr = str.split(/\s*,\s*/);
Trouble is that in Google Chrome (for Mac), it appends extra properties to the array.
Output from Chrome's debugger:
arr: Array
0: one
1: two
2: three
constructor: function Array()
index: undefined
input: undefined
length: 3
So if I iterate over the array with a for/in loop, it iterates over the new properties. Specifically the input and index properties. Using hasOwnProperty doesn't seem to help.
A fix would be to do a for loop based on the length of the Array. Still I'm wondering if anyone has insight into why Chrome behaves this way. Firefox and Safari don't have this issue.
function main(){
var delImage=document.createElement("img");
delImage.setAttribute("alt","Edit");
delImage.setAttribute("src","drop.png");
var position=newRow.rowIndex;
var typeElem=document.createElement("a");
typeElem.setAttribute("name","delete");
typeElem.setAttribute("href","#");
typeElem.appendChild(delImage);
typeElem.setAttribute('onclick',"delete(position)");
newRow.insertCell(lastCell).appendChild(typeElem);
}
function delete(pos){
alert(pos);
}
i am not able to call the delete function when anchor tag was clicked...what can i want to change to achieve this?
I'm grabbing the query string parameters and trying to do this:
var hello = unescape(helloQueryString);
and it returns:
this+is+the+string
instead of:
this is the string
Works great if %20's were in there, but it's +'s. Any way to decode these properly so they + signs move to be spaces?
Thanks.
Hi - I have this script on my html page:
parent.resizeTo(550,510);
I'd like to add to it so it positions the window in the middle of the screen. Also, I want to remove the address and tool bars (I've managed to hide the scrollbars by using body{overflow:hidden;}).
I know how to do this using JS upon opening a new window from the browser but this needs to work from clicking a link on a PDF.
Does anyone have any suggestions? Thank you!
Hi,
I have a problem with JQuery Context Menu ( link text ) and iframe.
If i use it inside, the context menu is naturaly shown inside. But it will be partialy shown.
I am searching how to resolve it.
Please note that the context menu only appear when i click on specific iframe's elements.
thanks :)
The concept is running multiple functions concurrently.
The reason is, I have a page which performs various actions through ajax. These actions includes making multiple backups of new files uploaded in the upload directory. But I want this process to be initiated by a moderator.
As this is a very lengthy process(might even take hours to complete), it blocks others ajax requests from executing, until this process complete.
I want to execute functions along with the previously executed function parallelly.
I am using jQuery's Ajax to sent initiate the request.
I have the following BaseClass defined:
function BaseClass (arg1,arg2,arg3) {
//constructor code here then -
var privateVar = 7500;
this.getPrivateVar = function() { return privateVar; };
}
I want to have the following subclass which allows changing privateVar like so:
function SubClass (arg1,arg2,arg3,privateVar) {
//constructor code here then -
var privateVar = privateVar;
}
SubClass.prototype = new BaseClass();
Now I want SubClass to inherit the getPrivateVar method. However, when I try this, it always returns 7500 which is the value in the BaseClass and not the value of privateVar.
In other words, is it possible to inherit a BaseClass's public methods but have any references in them refer to the SubClass's properties? And how would I do that?
Help me with regular expressions. I need to check the text on the hour and minute. That is the first case, the text can be from 0 to 12. In the second case, the text can be from 1 to 60.
this is my code:
var hourRegEx = /^([0-9]{2})$/; //You can fix this line of code?
$(document).ready(
function(){
$('form.form').submit(function(){
if( $('input.hour').val().match(hourRegEx) ){
return true;
}
return false;
});
});
In my case, the code says that, for example 52, too, the correct answer
I create windows like this:
var obj = document.createElement('div');
obj.className = 'window';
obj.style.width = 300 + 'px';
obj.style.height = 200 + 'px';
obj.style.left = 30 + 'px';
obj.style.top = 200 + 'px';
//and so on
and what I need is to attach some data to each window. The data will be grabbed via Ajax and displayed in the windows. How should I do it so that each window hold its own unique data?
I don't need to display the whole data every time and this data would need be organized before being displayed, so I can't just add it with innerHTML. I need a way to hold it somewhere else where I could easily get it and then display it with innerHTML.