I have a loop in Javascript, I want to run console.log() in a specific iteration, and then terminate. What is the best method to go about doing this? I'm wanting something like Perl's
I have another assignment where I have to make a few number games. I have done the rest of the program but I am stuck on writing this function. My problem is it asks to add the pattern to a string each time the loop completes. I dont get this. I understand this can be done using an array but we are asked not to use an array.
I know that it may be better to use the .each() function for this but I can't figure out how to iterate over elements that or not children or siblings of $(this). I have this code, and it works fine:
I have this source code (I get "data" via AJAX / JSON and it has the properties person.id and person.lastname).
[Code]...
I searched for sorting them in an alpabetical order. I saw solutions, fetching the whole data, but I am rendering the HTML ul list, so perhaps there are better ways to sort it? Or is it necessary, first to push all the li's to the ul? Isn't there a jQuery basic function for it?
i'm having a slight problem understand how to use this.myVar in an object. And I use prototype.
[Code]...
Does anyone know how I can use this.myvar within the function. I have tried binding and bindAsEventListener.But nothing I've done has been able to get the right value!
Instead I get every char of the string each in one alert message. How can I transform the String to an Array, or get in this case the two key-value pairs?
I am trying to assign values to a bunch of form fields. However, I don't want to loop through EVERY field in the form, just a specific subset of fields. The fields I am trying to change are all named similarly myField1, myField2, myField3.So, my thought is that I would like to use a for loop and loop through the appropriate fields by simply incrementing a variable and appending it to the end of the string "myField" in order to change the appropriate field.How can I evaluate "myField + iterator" into a useable reference to change the value of said field?
I wish to automate the population of a page by prefilling form values such as select boxes as well as fire off the change event after the value has been set. However there are at least 3/4 select boxes on one page which need populating automatically.
This works fine for the first element but not for subsequent elements all in one go when use the Trigger method of Jquery.
Now what do I write in this iteration loop to first get the text from the FIRST name and age box, in the first <table> (so I can work with tem). And in the next iteration loop get the SECOND <table>īs input fields text values?
I have firebug installed in my firefox browser, but I can't get console.log, console.debug or console.trace to work. My console window remains empty despite all my efforts. For example I have some code which throws up an alert box ( alert ('here is an alert') so I know 100% that it is being executed. If I now place the line console.log("please log this to the console");next to it, nothing gets written to the console. I also have firephp installed and this is logging to the console for my php code absolutely fine
I'm just getting started with nodejs. For now my purpose with this tech is to finish a book (The Definitive Guide to HTML5) where it's covering ajax and is using node.js to send the code back. I do want to learn the basics while I'm at it.
What I have so far: I understand that node.js lets me write my own web server. I understand that nodejs is actually 'C' and it just allows for us to write JS to make a web server and do other back-end tasks.
I've installed node.js on my windows 7 64 bit machine. I have found out that I can run a script on a node by right clicking it and selecting open with "Evented I/O for V8 Javascript".
What I want to know is how do I run node from the command line? What are the boundaries of the JS file that I write? From what I can tell, I can goo all over the place with my js file traversing my filesystem as I please. If this is true, how is it safe? It seems like it would be easy to hijack some simple js file and go all over the servers file system at will for a hacker....If someone could fill in these holes.
I have a bunch of dynamically created divs which I need to loop through and then display text inside which is obtained via AJAX.
<div class="appStatus" id="appStat_1>TEXT FROM PHP PAGE</div> <div class="appStatus" id="appStat_2>TEXT FROM PHP PAGE</div> <div class="appStatus" id="appStat_3>TEXT FROM PHP PAGE</div>
Basically, I want to loop through all divs where class = appStatus and on each iteration pull data from a PHP page (via AJAX) to display in the DIV. I need to send the value after the _ of the id (which I can obtain using substring) with the AJAX request in order to return the correct text.For some reason.I know that I need to do something with
The XXX function here would interpolate the values of any variables named with a @ prefix into the string. Why @? Why not?
So using my favorite JavaScript console (FireBug), I typed the following and ran it:
x = "hello world"; y = 42; z = "--@x/@y--"
z = z.replace(/@(w+)/g, function (dummy, v) { return eval(v); });
alert(z);
And it works. The alert box shows "--hello world/42--" as expected. Okay, so now let's turn it into a function:
x = "hello world"; y = 42;
function XXX(s) { return s.replace(/@(w+)/g, function (dummy, v) { return eval(v); }); }
alert(XXX("!!!@x~~~@y!!!"));
And again, it works. The alert box shows "!!!hello world~~~42!!!" as expected. I should be able now to just drop this *same* code into a <scriptsection of a web page, right?
Wrong. If I take the *same* code as my second example and plop it in a web page, the alert does not show the same thing as when in FireBug's console. It shows the same string passed to XXX, unchanged.
Other experimentation tells me that when placed in a web page, the anonymous function to do the eval call is never invoked, which suggests that the regular expression didn't match.
I've only tried this in FireFox 2 and IE 7, but if it doesn't work properly in either of those, I really don't care about the other browsers.
My guess is there is a difference in the execution environment of FireBug's console (or likely, any JavaScript console) and the execution environment of a web page. The questions are what is that difference, and how do I make my XXX function work properly?
<script> $('#text').load('test.html h1'); // loads h1 content out of test.html - works fine $('#text h1').append('test'); // should append 'test' to h1 - does nothing!
Code: for (var ur=longestRow; ur>1; ur-- ) // adjust rows above it { console.log("going to call spaceRowAbove("+ur+")"); spaceRowAbove(ur); } If Firebug is enabled the message is logged and the function is executed.If Firebug is NOT enabled, the function is not executed.If the log statement is commented out, the function IS executed.Wouldn't it be more reasonable for the interpreter to ignore just the console call, rather than the whole loop?Or is it just me and my Firefox 3.5.5?
Firefox has a Javascript Console that has 3 panels besides "All" and "Clear": "Errors", "Warnings", "Message".
Does anyone know a way to log a message in the Message panel with JavaScript? That would really help debugging. I know there's a way involving XPCOM, but that only works with "trusted" scripts, and scripts loaded thru html aren't trusted.
I am getting $document.ready(function() not defined in the firebug console. I have seen that in most cases this is caused when the jQuery core is missing or the path is invalid. I do not believe this is the problem in my case becuase firebug shows the code as being loaded successfully and it is readable.
I have the following scripts in my head; <script type="text/javascript" src="jquery-1.4.2.min.js"></script> <script type="text/javascript" src="jquery.validate.js"></script> <script type="text/javascript"> jQuery.validator.addMethod( "selectNone", function(value, element) { if (element.value == "none") { return false; }}, .....