I'm trying to understand if I can debug a stand alone .js file which doesn't interact with browser. Is there any way to just load it and debug or I will be forced to encapsulate it into html file?
I'm loading in 3 images (named 1.jpg, 2.jpg, 3jpg) dynamically to 3 divs called "div1", "div2" and "div3".
function loadImages() {
for (var i = 1; i < 3; i++ ) {
var img = document.createElement("img");
img.src = "vegetables/"+i+".jpg";
img.id = "a"+i+"";
var divName = "div"+i+"";
document.getElementById(divName).appendChild(img);
}
}
That works, but the removing part I can't seem to get to work..
function removeImages() {
for (var i = 1; i < 3; i++ ) {
var oldImages = "a"+i+"";
var divName = "div"+i+"";
document.getElementById(divName).removeChild(oldImages);
}
}
Thank you.
I'm retrieving an array of objects from a hidden html input field. The string I'm getting is:
"{"id":"1234","name":"john smith","email":"[email protected]"},{"id":"4431","name":"marry doe","email":"[email protected]"}"
Now I need to pass this as an array of objects again. How do I convert this string into array of objects?
I am using google maps api v3 and have an array of arrays object:
MVCArray.<MVCArray.<LatLng>>
I want to iterate over this. I see that MVCArray has a method forEach which uses a call back, but I have no idea how to use this (I haven't done much js). The api defines this method as follows:
forEach(callback:function(*, number)))
Could somebody please show me an example of how to use this given an MVCArray of MVCArrays?
I am storing a JSON string in the database that represents a set of properties. In the code behind, I export it and use it for some custom logic. Essentially, I am using it only as a storage mechanism. I understand XML is better suited for this but I read that JSON is faster and preferred.
Is it a good practice to use JSON if the intention is not to use the string on the client side?
I was adding recent videos gadget on my blog. In that widget i was supposed to add this line
<script src="/feeds/posts/default?orderby=published&alt=json-in-script&callback=showrecentpostswiththumbs">
also, i added another script which was having the method showrecentpostswiththumbs [ used in callback ]. Please let me know what does above syntax do?
I am trying to call a function "makeQuery" and it's not working, FireBug is telling me:
missing ; before statement
[Break on this error] makeQuery(this.id){\n
I don't quite understand where it wants me to put the ";"
$(".predicate").click(function () {
makeQuery(this.id){
alert(this.id);
}
});
function makeQuery(value){
queryString = queryString+"val="+value+"&";
variables = variables+1;
alert(queryString);
alert(variables);
}
I am creating a private message system to allow users to communicate between one another within the context of the website (ie, not emails).
I have created this function to handle all my form submissions. I would like to achieve a solution without modifying this function (ideally).
$("form.reload").submit(function(){
alert($(this).serialize()); /* Debugging */
$.post($(this).attr("action"),
$(this).serialize()
,function(data){
if(data){
$("#error").html(data);
}else{
location.reload();
};
});
return false;
});
Within my form I am using JQuery Autocomplete to find usernames. This function works perfectly. My first solution was to add buttons within the form with the necessary values.
select: function(event, ui) {
$("#message_to").append("<input type=\"button\" class=\"recipient\" name=\"recipients[]\" value=\"" + ui.item.label + "\" onclick=\"$(this).remove()\" />");
}
<form method="post" action="/messages-create">
<div id="message_to"></div>
</div>
For some reason the values of recipients are not getting posted.
My second solution was to add to a post array that already existed in the form
select: function(event, ui) {
$(input[name=recipeients[]).val = ui.item.label; /* Need to add to array, not replace! */
$("#message_to").append("<input type=\"button\" class=\"recipient\" name=\"recipient\" value=\"" + ui.item.label + "\" onclick=\"$(this).remove(); /* Remove from recipients */\" />");
}
<form method="post" action="/messages-create" class="reload">
<input type="hidden" name="recipients[]" value="" />
<div id="message_to"></div>
</div>
This works ok, but I have been unable to work out how to append to the recipients[] array only replace with the new label. Moving on from this, I also need to know how to then remove this value from the array.
Thanks in advance!
Hi, I'm using CurvyCorners to make my corners curvy in IE, only thing is that when it reads the CSS it takes all the webkit properties and shows me an alert curvyCorners.alert("No object with ID " + arg + " exists yet.\nCall curvyCorners(settings, obj) when it is created.");.
How can I just set this if statement to do nothing?
if (j === null)
do nothing(); //but in real script
Thanks :)
I need a way to turn my 2 character string dates (i.e. '04/10/2010' & '05/24/2010') into an integers to see if one is greater than the other. If the user enters an end date that is less than the begin date I need to popup an "invalid date range" error.
Ok, so I have a "navigation" div and "content" div.
When something on the navigation is clicked, I fade in the content div with the new data.
Now, I would like to have the old data returned when the user hits the "back" button on his/her browser, but I'm having a hard time doing this.
I know I can set the content to be a named anchor, so they stay on the same page with a breadcrumb trail. However, that's as far as I get. Can I listen for a back button click? Can I set content to display when a certain anchor name is reached?
Thanks in advance for your help, SO.
Is there a better way other than looping to find data in JSON? It's for edit and delete.
for(var k in objJsonResp) {
if (objJsonResp[k].txtId == id) {
if (action == 'delete') {
objJsonResp.splice(k,1);
} else {
objJsonResp[k] = newVal;
}
break;
}
}
The data is arranged as list of maps.
Like:
[{id:value, pId:value, cId:value,...}, {id:value, pId:value, cId:value}, ...]
i have an asp.net form and an asp:textbox. i have a problem when the user presses and HOLDS a key down. the user selects the text box and then presses and holds '9' until the text box fills with 9s.
Is there any way to detect this situation?
Is there a way to stop key repeats when the key is held down?
I have a very simple function that takes a list of comma separated (x,y) points and imports them into a graph. I have FF, Chrome and IE8 installed. I use IETester to test for IE6 and IE7.
// Import Data
this.Import = function(data) {
alert("Data in: "+data);
var d;
// Make sure the first and the last are start/ending parenthesis
if ( (data[0] != '(') || (data[data.length-1] != ')') ) {
alert("After if: "+data[0]+" "+data[data.length-1]);
return false;
}
...
In Chrome, FF and IE8, I don't see the "After if:" alert.
In IE6 and IE7, I see the following two alerts:
Data in: (52,16),(100,90)
After if: undefined undefined
The "Data in" alert matches in all browsers.
Any ideas?
I'm working on a simple subtraction problem, but unfortunately it keeps returning NaN
Here is the function
function subtraction(a, b) {
var regexp = /[$][,]/g;
a = a.replace(regexp, "");
b - b.replace(regexp, "");
var _a = parseFloat(a);
var _b = parseFloat(b);
return _a - _b;
}
And here is how I'm calling it.
txtGoodWill.value = subtraction(txtSellingPrice.value, txtBalanceSheet.value);
The numbers that get submitted to the function are ONLY Currency (IE: $2,000 or $20, etc)
Now I know that I cannot subtract numbers with a $ or a ,, but I can't for the life of me figure out why they are getting evaluated in the equasion.
Hi this is my pice of code:
<div style="overflow: hidden; width: 445px;">[IMG]http://i29.tinypic.com/mydog.png[/IMG] tak si to http://i29.tinypic.com/mycat.png Lorem ipsum loremai <img width="15" border="0" align="middle" src="images/smejo.gif" valign="middle"/> <img src=http://www.example.com/index.png alt> <img src="http://www.example.com/index.png" alt> <a href="#reakcia" title="reagovat na temu"><span class="poradna-tl-reaguj"><reaction> </span></a></div>
</td> </tr><img src=http://www.example.com/index.png alt><img src="http://www.example.com/index.png" alt>
and i need regex pattern to replace ONLY text image links with image without touch of inner url tags.
But i can't use "Lookbehind" or possessive quantifiers because JS don't support them=/
So i want to catch only "http://i29.tinypic.com/mydog.png" and "http://i29.tinypic.com/mycat.png".
I using array method to replacing (will be greasemonkey script.)
Many Thanks
Hi everyone,
can I convert a string to a html object?
like:
string s = '<div id="myDiv"></div>';
var htmlObject = s.toHtmlObject;
so that i can later on get it by id and do some changing in its style
var ho = document.getElementById("myDiv").style.marginTop = something;
Thanx a million in advance,
Lina
I'm using the function below to change the img src. It's an array of ten images. When going through the loop, using break points, the images don't all update on the page immediately. Some of them do. If I inspect the unchanged images on the page (while paused at a breakpoint), the src has changed, but the image hasn't changed yet. All of the unchanged images get updated correctly when the function ends.
Anyone know why they don't all get updated instantly and how I can force them to update?
Also, is there a way I can hold off the updates of all of them until they're all reassigned and thus have them all update on the "simultaneously"? Here's my function.
function mainFunction(){
finalSet = calculateSet();
for ( var int = 0; int < finalSet.length; int++) {
var fileName = "cardImg" + (int);
document.getElementById(fileName).src = "images/cards/" + finalSet[int].name + ".jpg";
}
}
Thanks for the help.
Dale
I have a large module written in JS which uses Canvas to draw and animate trees. This module was written for a product which is now being migrated to flex.
Is there a way in flex to embed this JS module as is? Or would I have to rewrite the whole module in AS3 (shudder)? Further, if embedding is possible, would user interactions (mouse clicks) etc. work seamlessly?
An example of the tree structure I am talking about can be found here - http://thejit.org
I need some help to understand how this code was obfusticated. The code is:
<a id="suggest" href="#" ajaxify="/ajax/social_graph/invite_dialog.php?class=FanManager&node_id=108463912505356" class=" profile_action actionspro_a" rel="dialog-post">Suggest to Friends</a>
And the obfustication is:
\x3c\x61\x20\x69\x64\x3d\x22\x73\x75\x67\x67\x65\x73\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x23\x22\x20\x61\x6a\x61\x78\x69\x66\x79\x3d\x22\x2f\x61\x6a\x61\x78\x2f\x73\x6f\x63\x69\x61\x6c\x5f\x67\x72\x61\x70\x68\x2f\x69\x6e\x76\x69\x74\x65\x5f\x64\x69\x61\x6c\x6f\x67\x2e\x70\x68\x70\x3f\x63\x6c\x61\x73\x73\x3d\x46\x61\x6e\x4d\x61\x6e\x61\x67\x65\x72\x26\x61\x6d\x70\x3b\x6e\x6f\x64\x65\x5f\x69\x64\x3d\x31\x30\x38\x34\x36\x33\x39\x31\x32\x35\x30\x35\x33\x35\x36\x22\x20\x63\x6c\x61\x73\x73\x3d\x22\x20\x70\x72\x6f\x66\x69\x6c\x65\x5f\x61\x63\x74\x69\x6f\x6e\x20\x61\x63\x74\x69\x6f\x6e\x73\x70\x72\x6f\x5f\x61\x22\x20\x72\x65\x6c\x3d\x22\x64\x69\x61\x6c\x6f\x67\x2d\x70\x6f\x73\x74\x22\x3e\x53\x75\x67\x67\x65\x73\x74\x20\x74\x6f\x20\x46\x72\x69\x65\x6e\x64\x73\x3c\x2f\x61\x3e","\x73\x75\x67\x67\x65\x73\x74
Now I used unescape on the above obfusticated code to read it. What I want to know is what exactly was used to obfusticate the code like that? Basically, I need to customize the readable code to the same obfustication.
Any help would be greatly appreciated.
Hi,
I have a simple code fragment in JS working with prototype inheritance.
function object(o) {
function F() {}
F.prototype = o;
return new F();
}
//the following code block has a alternate version
var mammal = {
color: "brown",
getColor: function() {
return this.color;
}
}
var myCat = object(mammal);
myCat.meow = function(){return "meow";}
that worked fine but adding this:
mammal.prototype.kindOf = "predator";
does not. ("mammal.prototype is undefined")
Since I guessed that object maybe have no prototype I rewrote it, replacing the var mammal={... block with:
function mammal() {
this.color = "brown";
this.getColor = function() { return this.color; }
}
which gave me a bunch of other errors:
"Function.prototype.toString called on incompatible object"
and if I try to call _myCat.getColor()
"myCat.getColor is not a function"
Now I am totally confused. After reading Crockford, and Flanagan I did not get the solution for the errors. So it would be great if somebody knows...
- why is the prototype undefined in the first example (which is foremost concern; I thought the prototype of explicitly set in the object() function)
- why get I these strange errors trying to use the mammal function as prototype object in the object() function?
Edit by the Creator of the Question: These two links helped a lot too:
Prototypes_in_JavaScript on the spheredev wiki explains the way the prototype property works relativily simple. What it lacks is some try-out code examples. Some good examples are provided by Morris John's Article. I personally find the explanations are not that easy as in the first link, but still very good.
The most difficult part even after I actually got it is really not to confuse the .prototype propery with the internal [[Prototype]] of an object.
Hi, I am trying to optimize my program. I think I understand the basics of closure. I am confused about the scope chain though.
I know that in general you want a low scope (to access variables quickly).
Say I have the following object:
var my_object = (function(){
//private variables
var a_private = 0;
return{ //public
//public variables
a_public : 1,
//public methods
some_public : function(){
debugger;
alert(this.a_public);
alert(a_private);
};
};
})();
My understanding is that if I am in the some_public method I can access the private variables faster than the public ones. Is this correct?
My confusion comes with the scope level of this.
When the code is stopped at debugger, firebug shows the public variable inside the this keyword. The this word is not inside a scope level.
How fast is accessing this? Right now I am storing any this.properties as another local variable to avoid accessing it multiple times.
Thanks very much!