Search Results

Search found 23794 results on 952 pages for 'serverside javascript'.

Page 7/952 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • shuffling array javascript

    - by Dennis Callanan
    <!doctype html> <html lang="en"> <head> <meta charset="utf=8" /> <title>Blackjack</title> <link rel="stylesheet" href="blackjack.css" /> <script type="text/javascript"> var H2 = 2; var S2 = 2; var D2 = 2; var C2 = 2; var H3 = 3; var S3 = 3; var D3 = 3; var C3 = 3; var deck = new Array(H2, S2, D2, C2, H3, S3, D3, C3); var new_deck = new Array(); var r; document.write("deck = ") for (r =0; r<deck.length; r++){ document.write(deck[r]); } document.write("</br>") document.write("new deck = ") for (r=0; r<new_deck.length; r++){ document.write(new_deck[r]); } document.write("</br>") for (r=0;r<deck.length;r++){ var randomindex = Math.floor(Math.random()*deck.length); new_deck.push(randomindex) deck.pop(randomindex) } document.write("deck = ") for (r =0; r<deck.length; r++){ document.write(deck[r]); } document.write("</br>") document.write("new deck = ") for (r=0; r<new_deck.length; r++){ document.write(new_deck[r]); } document.write("</br>") </script> </head> <body> </body> </html> Obviously this isn't the full Blackjack game here. It's just a test to see if shuffling the array works by printing the contents of both decks (arrays) before and after the shuffle. I'm only using 8 cards at the moment, 4 2's and 4 3's. What I am getting from this is: deck = 22223333 new deck = deck = 2222 new deck = 7502 What I'm hoping to get is: deck = 22223333 new deck = deck = new deck = 23232323 (or any of the 8 numbers, generated randomly) So it should be shuffling those 8 cards, what am I doing wrong? I'm only new to javascript but I've used some python before. I've done something similar in python and worked perfectly, but I'm not sure what's wrong here. Thanks for any answers in advance!!

    Read the article

  • Javascript get anchor href on click

    - by Infinity
    Hello guys! How can I get the href of an anchor when I click on it using javascript? I did the following: document.onClick = myFunc(); function myFunc() { } But how to extend the function to respond only to clicks on anchors and get the href?

    Read the article

  • javascript object's - private methods: which way is better.

    - by Praveen Prasad
    (function () { function User() { //some properties } //private fn 1 User.prototype._aPrivateFn = function () { //private function defined just like a public function, //for convetion underscore character is added } //private function type 2 //a closure function _anotherPrivateFunction() { // do something } //public function User.prototype.APublicFunction = function () { //call private fn1 this._aPrivateFn(); //call private fn2 _anotherPrivateFunction(); } window.UserX = User; })(); //which of the two ways of defining private methods of a javascript object is better way, specially in sense of memory management and performance.

    Read the article

  • Why does the JavaScript need to start with ";" ?

    - by TK
    I have recently noticed that a lot of JavaScript files on the web starts with ; immediately following the comment section. For example, this jQuery plugin's code starts with /** * jQuery.ScrollTo * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com * Dual licensed under MIT and GPL. * Date: 9/11/2008 .... skipping several lines for brevity... * * @desc Scroll on both axes, to different values * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } ); */ ;(function( $ ){ Why does the file needs to start with ;? I see this convention on server-side JavaScript files as well. What is an advantage and disadvantage of doing this?

    Read the article

  • JavaScript local alias pattern

    - by Latest Microsoft Blogs
    Here’s a little pattern that is fairly common from JavaScript developers but that is not very well known from C# developers or people doing only occasional JavaScript development. In C#, you can use a “using” directive to create aliases of namespaces Read More......(read more)

    Read the article

  • Best IDE for HTML, CSS, and Javascript for mac [closed]

    - by jon2512chua
    I'm currently looking to move to using an IDE for web development. The options I'm considering are: Aptana Studio Coda Expresso Please base your answers on the following criteria, in descending order of importance: Supports HTML, CSS, JavaScript Powerful (having good code completion, good debugger, great syntax highlighting etc) Fast and light Supports HTML5, CSS3, and major JavaScript frameworks (JQuery or YUI) Great design (both usability and aesthetics) Supports PHP, Ruby, and Python Has Git integrated I've updated the question to be more objective. I'm mainly looking for an answer that addresses how well each of the IDEs addresses my criteria.

    Read the article

  • Learning how to integrate JavaScript with other languages

    - by beacon
    After learning JavaScript syntax, what are some good resources for learning about integrating JavaScript with other languages (HTML, XML, CSS, PHP) to create real, useful applications? I'm most interested in reading articles or other people's code - not so interested in books. Basically, I'm looking to move from programming puzzle-solvers to programming complex applications and could use some advice.

    Read the article

  • TypeScript or JavaScript for noob web developer [closed]

    - by Phil Murray
    Following the recent release by Microsoft of TypeScript I was wondering if this is something that should be considered for a experienced WinForm and XAML developer looking to get into more web development. From reviewing a number of sites and videos online it appears that the type system for TypeScript makes more sense to me as a thick client developer than the dynamic type system in Javascript. I understand that Typescript compiles down to JavaScript but it appears that the learning curve is shallower due to the current tooling provided by Microsoft. What are your thoughts?

    Read the article

  • Tools for building long-running Javascript webapp

    - by FilipK
    Given my lack of familiarity with such tools, could you suggest what tools / frameworks would be suitable for developing a long-running JavaScript webapp? The webapp would display a constantly updating chart. The updates would come through WebSockets (preferably) or XmlHttpRequest. I know and have written JavaScript with JQuery, but for this task I assume something like backbone.js or ExtJS would be appropriate (or maybe not?).

    Read the article

  • JavaScript: catching URI change

    - by ptrn
    I have a site where I'm using hash based parameters, eg. http://url.of.site/#param1=123 What I want When the user manually changes the URI to eg. http://url.of.site/#param1=789 When the user enters this URI, the event is caught by the JavaScript, and the appropriate functions are called. Basically, what I'm wondering about is; is there an event listener for this? Or would I have to periodically check the URI to see if it has been changed? I'm already using the current jQuery API, if that helps. _L

    Read the article

  • JavaScript inline events syntax

    - by Mic
    Is there any reason to use one of the following more than the others: <input type="button" value="b1" onclick="manageClick(this)" /> <input type="button" value="b2" onclick="manageClick(this);" /> <input type="button" value="b2" onclick="manageClick(this);return false;" /> <input type="button" value="b3" onclick="return manageClick(this);" /> <input type="button" value="b4" onclick="javascript:return manageClick(this);" /> And please do not spend your valuable time to tell me to use jQuery or attachEvent/addEventListener. It's not really the objective of my question.

    Read the article

  • Leaving out type="text/javascript" language="javascript"

    - by coffeeaddict
    Most of the script tags I create, I always include type="text/javascript" language="javascript" in the tag. My boss however does not. Sometimes he excludes both, sometimes just has language=javascript even without the quotes Now we have not had an issue in any of the major browsers with his tags. I'm talking about all versions of IE, FF, Safari, and Chrome. Personally I feel it's laziness and just totally improper and bad coding practice to leave stuff out like this even if it works without it. Anyone know if both should be included or just one or is it ok to leave both out in ASP.NET?

    Read the article

  • JavaScript Intellisene Problem?

    - by James Wiseman
    I've got an issue with JavaScript intellisense in Visual Web Developer 2008, which I'm starting to believe is "just one of those things", but thought I'd ask here just to check. I have a file MyOtherFile.js with a function GetRandomNumber() defined like so: function GetRandomNumber() { /// <summary> /// Summary description for GetRandomNumber /// </summary> return Math.random(); } When I reference this from another file, screen.js (/// <reference path="MyOtherFile.js" />) I get the intellisense as expected with the summary text as above. If, however, I call the function GetRandomNumber from within its own file (MyOtherFile.js) then I don't get the sumamry description. Any thoughts? Thanks.

    Read the article

  • Test whether image loaded correctly with JavaScript

    - by johkar
    I have an image deployed on several application servers (green up arrow: uparrow.gif). I have an application server status page where I list out all the servers and with a corresponding image where the image's source is the uparrow.gif for that server. If the image does not load (server down) I would like to switch to a red down arrow (downarrow.gif). Is there a way to check whether an image loaded or not with straight JavaScript (no JS libraries etc)? I would imagine I would set an interval for it to continue checking if the user were on the page. Thanks.

    Read the article

  • Modify url for bookmarking using JavaScript

    - by jamesaharvey
    I'm exploring my options for modifying urls in the browser bar for bookmarking purposes. Ideally, I'd like to add querystring parameters and cannot determine if this is even possible. I don't want the page to refresh and want to add querystring values on link clicks, ajax calls, etc. If I can't add querystring parameters, then I'd like to add hash values (http:://someurl.com#hash-value). How should I go about doing this? Should I use plain JavaScript or a framework (jquery, prototype, etc.) and/or framework plugin.

    Read the article

  • Running custom Javascript on every page in Mozilla Firefox

    - by saturn
    I have a custom piece of Javascript which I would like to run on every web page from specific domains, or perhaps simply on every web page. (If you are wondering: it is not malicious. It allows to display formulas by using MathJax.) Is that possible? I tried including it in userContent.css, that of course did not work. A simple Greasemonkey script I tried did not insert it. Is it because of the security precautions? (Which would be very logical). Still, there should be a way to do it on the machine I physically control, by changing something in Mozilla chrome directory, shouldn't it? Anyway, how can I do this for myself?

    Read the article

  • Why javascript IF only works one time?

    - by Emily
    I have javascript code which copy the value of input file and past it in the text box in real time. <script> function copyit(){ var thephoto=document.getElementById('thephoto').value; var fileonchange=document.getElementById('fileonchange').value; if(!thephoto==fileonchange){ document.getElementById('fileonchange').value=thephoto; } } window.setInterval("copyit()", 500); </script> Choose File : <input type="file" id="thephoto"><br> Here Is the file name : <input type="text" id="fileonchange"> Sadly this only works one time and then stops pasting the value when changing the file again. ( i mean you should reload the page to works again) Is IF has a cache or something? you can try the code by yourself to see. Thank you all

    Read the article

  • click() (javascript) method is not working in FF

    - by Bragaadeesh
    Hi, The following code is throwing two alerts as expected in IE but not in Firefox. Please help. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <SCRIPT LANGUAGE="JavaScript"> <!-- function myFunction(){ alert('myfunc'); document.getElementById('mylabel').click(); } //--> </SCRIPT> </HEAD> <BODY> <p id='mylabel' onclick="alert('you reached');"></p> <input type='button' value="Click me" onclick='myFunction();'/> </BODY> </HTML> Thanks

    Read the article

  • Drag and drop an image from desktop to a web text editor (implementation in javascript)

    - by fatmatto
    I tried to write reasonably short title but i failed i guess.. Hi everybody here's what i'm trying to do: I want to implement a web text editor able to recognize when the user drag a image file over it's editing surface and it automa(gically) starts the upload and insert the image near the cursor position. In other words i don't want the user to do the usual "insert-image-browse-ok". Atm i am not very good at javascript ... i know JQuery but i have not a clear idea about how to implement this... i don't know if there's an event handler able to help me in this situation... if not then there should be i think or web apps would miss some kind of interactivity. I've heard miracles about HTML5 could it help me? I've seen such things in Google Wave but that surface doesn't seem to be a form field... google lab's black magic i guess.... Thank you in advance.

    Read the article

  • Switching Javascript Function states

    - by webzide
    Dear experts, I would like to implement a API of Javascript that sort of resemble a light switch. For instance, there are two buttons on the actual HTML page act as the UI. Both of the buttons have event handlers that invokes a different function. Each function have codes that act like a state, for instance. button1.onclick=function (){ $("div").click( //code effects 2 ) } button2.onclick=function (){ $("div").click( //Code effects 2 ) } I the code works fine on the surface but the 2 state functions overlap. the effects is going to take place for the rest of the way until the next reload of the document. Basically what I want to achieve is that when 1 button is clicked, it will switch "OFF" the state of function invoked by the other button and vice versa. Thus, the effects achieved are unique are not overlapped. Is there anyway to achieve this or could any experts point me to the right direction. Thanks in advance.

    Read the article

  • Javascript parent page redirection from iframe.

    - by Danil
    Hello to all. I need to implement parent page redirection from iframe. I know that it is impossible to do in different domains due to browsers security. However I found that links have target attribute and tried to use it in the following way: <a href="http://google.com" target="_top" id="testParentRedirect">someLink</a> It works fine if I click this link manually, but I couldn't find cross-browser solution to simulate it using javascript. document.getElementById('testParentRedirect').click(); This works fine in IE, however Firefox and Safary don't know click function :). I tried to work with jquery, but for some reason they don't simulate click event for links. (see following post) I couldn't find any appropriate solution on stackoverflow. Maybe someone could help me in it. I will appreciate it. :)

    Read the article

  • Detecting support for a given JavaScript event?

    - by Will
    I'm interested in using the JavaScript hashchange event to monitor changes in the URL's fragment identifier. I'm aware of Really Simple History and the jQuery plugins for this. However, I've reached the conclusion that in my particular project it's not really worth the added overhead of another JS file. What I would like to do instead is take the "progressive enhancement" route. That is, I want to test whether the hashchange event is supported by the visitor's browser, and write my code to use it if it's available, as an enhancement rather than a core feature. IE 8, Firefox 3.6, and Chrome 4.1.249 support it, and that accounts for about 20% of my site's traffic. So, uh ... is there some way to test whether a browser supports a particular event? Thanks.

    Read the article

  • javascript removeChild(this) from input[type="submit"] onclick breaks future use of form.submit() un

    - by maximumduncan
    I have come across some strange behaviour, and I'm assuming a bug in firefox, when removing a input submit element from the DOM from within the click event. The following code reproduces the issue: <form name="test_form"> <input type="submit" value="remove me" onclick="this.parentNode.removeChild(this);" /> <input type="submit" value="submit normally" /> <input type="button" value="submit via js" onclick="document.test_form.submit();" /> </form> To reproduce: Click "remove me" Click "submit via js". Note that the form does not get submitted, this is the problem. Click "submit normally". Note that the form still gets submitted normally. It appears that, under Firefox, if you remove a submit button from within the click event it puts the form in an invalid state so that any future calls to form.submit() are simply ignored. But it is a javascript-specific issue as normal submit buttons within this form still function fine. To be honest, this is such a simple example of this issue that I was expecting the internet to be awash with other people exeriencing it, but so far searching has yealded nothing useful. Has anyone else experienced this and if so, did you get to the bottom of it? Many thanks

    Read the article

  • How to create a variadic (with variable length argument list) function wrapper in JavaScript

    - by U-D13
    The intention is to build a wrapper to provide a consistent method of calling native functions with variable arity on various script hosts - so that the script could be executed in a browser as well as in the Windows Script Host or other script engines. I am aware of 3 methods of which each one has its own drawbacks. eval() method: function wrapper () { var str = ''; for (var i=0; i<arguments.lenght; i++) str += (str ?', ':'') + ',arguments['+i+']'; return eval('[native_function] ('+str+')'); } switch() method: function wrapper () { switch (arguments.lenght) { case 0: return [native_function] (arguments[0]); break; case 1: return [native_function] (arguments[0], arguments[1]); break; ... case n: return [native_function] (arguments[0], arguments[1], ... arguments[n]); } } apply() method: function wrapper () { return [native_function].apply([native_function_namespace], arguments); } What's wrong with them you ask? Well, shall we delve into all the reasons why eval() is evil? And also all the string concatenation... Not a solution to be labeled "elegant". One can never know the maximum n and thus how many cases to prepare. This also would strech the script to immense proportions and sin against the holy DRY principle. The script could get executed on older (pre- JavaScript 1.3 / ECMA-262-3) engines that don't support the apply() method. Now the question part: is there any another solution out there?

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >