[link] Ten Oddities And Secrets About JavaScript


QuoteJavascript. At once bizarre and yet beautiful, it is surely the programming language that Pablo Picasso would have invented. Null is apparently an object, an empty array is apparently equal to false, and functions are bandied around as though they were tennis balls.

This article is aimed at intermediate developers who are curious about more advanced Javascript. It is a collection of Javascripts oddities and well-kept secrets. Some sections will hopefully give you insight into how these curiosities can be useful to your code, while other sections are pure WTF material. So, lets get started.
Posted On: Thursday 29th of November 2012 08:30:24 PM Total Views:  407
View Complete with Replies

RELATED TOPICS OF JavaScript PROGRAMMING LANGUAGE




pop-up small window & link action in the textfield

hi! just wanna know 1.the coding to pop- up small window when a user click on the link button e-Account 2. is it possible to put an action in the textfield that will enable user to link to the other pages From the attached image, when the user click the "DETAIL" text, a small window that contain the detail of the article will pop-up in the separate window This post has been edited by taf: 21 August 2007 - 01:02 AM
VIEWS ON THIS POST

265

Posted on:

Monday 26th November 2012
View Replies!

Apply variable to hyperlink label

I need to replace "Link Text" with the value in the variable (myNewString). myNewString is just text e.g hello code document.write(myNewString); Link text i need some thing like the below or even a php version of it (myNewString) --this syntax is incorrect it seems THANKS!!!!!!!!
VIEWS ON THIS POST

139

Posted on:

Monday 26th November 2012
View Replies!

Graphic buttons / sounds and links

Could anyone tell me what would be the code for this effect please. I want the code for a button effect The button is for a graphic button, on clicking it it changes its graphic to an ('on' image), plays a sound effect, then changes graphic to the first image('off' image), then it goes to a link. Files would be Images/offbutton.jpg Images/onbutton.jpg sound/buttonclick.wav Thank you for any help given.
VIEWS ON THIS POST

114

Posted on:

Monday 26th November 2012
View Replies!

HTML link that calls JavaScript function

I am currently trying to make an html link that will add elements (specifically, drop down menus) to the current page when you click it. Since I am adding all the elements to the page using JavaScript, I'm not sure how to set up the link to call a function rather than go to a different page. I've seen people set the href attribute to the function they want, so I tried that and it didn't work. I've also seen a way that involves using onclick and making the link follow the onclick, not go to a different page. In summary, how do you create/edit a link (from javascript) to make it use a javascript function rather than go to a different page This is what I have currently (that concerns the link): var link = document.createElement('a'); eval("link.setAttribute('href', 'javascript:addHours(" + dayDiv + ")');");
VIEWS ON THIS POST

158

Posted on:

Monday 26th November 2012
View Replies!

Random images/links without repeating

I have a web page that contains a bunch of advertisements. What I need to do it randomly shuffle these images each time the page is refreshed. I cannot have any repeating ads. Here is the code I have now.... it repeats images. function random() { images = new Array(3); images[0] = ""; images[1] = ""; images[2] = ""; for(var i = 0; i < images.length; i++) { index = Math.floor(Math.random() * images.length); document.write(images[index]); } } random(); I would like to keep the code as simple as possible.
VIEWS ON THIS POST

255

Posted on:

Monday 26th November 2012
View Replies!

Submit Button linking to another page

How would I go about creating the coding for a submit button that links to another page And I would I go about creating the coding for the reset button that resets the page I go about creating a code to do so, but it never works. Here is the coding I have for the submit button:
VIEWS ON THIS POST

186

Posted on:

Monday 26th November 2012
View Replies!

need file upload by clicking a link instead of button

hi, I need an way to upload a file by clicking a link instead of button(). This feature has been newly added to GMail, to attached a file we need to click a link. Any ideas or code of how this can be done are needed.
VIEWS ON THIS POST

153

Posted on:

Monday 26th November 2012
View Replies!

open links in parent window (from child)?

I have popup window containing links called from the parent. If someone clicks a link in the child window (popup) I want it to open in the parent window (original window). Is this possible and can somebody please show me what script to add to child window to do it please My popup (so you can see) go here http://herproom.5.forumer.com/index.php and click the link 'Veiw Active Topics' near the top. popup has green snake background.
VIEWS ON THIS POST

118

Posted on:

Tuesday 27th November 2012
View Replies!

Help with hyperlinks!

, I am trying to integrate a link in a Visio diagram to a specific remote desktop session. Basically, I want to be able to click a server in my drawing, and have remote desktop come up with a connection to that server. I know that the syntax of the command is: mstsc /v SERVER NAME However, I cannot get that to work in the insert hyperlink window in Visio.
VIEWS ON THIS POST

202

Posted on:

Tuesday 27th November 2012
View Replies!

Null hyperlink: OK?

fellow web designers. I used Dreamweaver to place a rollover image on one of my web pages. It uses Javascript. When I looked at the code it had written, it includes the following null hyperlink on the image: [HTML][/HTML] Is there any chance this null link could cause errors on some browsers I have only tested the page on IE6.
VIEWS ON THIS POST

121

Posted on:

Tuesday 27th November 2012
View Replies!

Hyperlink POST using Javascript

I am trying to write a page that uses Javascript to post a variable to another page so that it does not appear in the address bar. There are pages out there that almost do what I would like them to do, but are confusing... part of the reason for this is that I am new to Javascript. The Problem: I currently have a page named "Document List" that has a list of hyperlinks as follows: Show Document 1 Show Document 2 Show Document 3 Show Document 4 I have read a post to these forums at http://www.daniweb.com/techtalkforums/thread32396.html , but it does not quite do what I am looking for because the "variable" value does not seem to be POSTED to the new page. So the end game here is to replace these hyperlinks with some mechanism (Forms or otherwise) to avoid the situation that a user replaces the "variable" value in the address bar. Javascript seems to be able to do it, but I cannot seem to get the thing to work. Are you able to assist Thank you in advance
VIEWS ON THIS POST

172

Posted on:

Tuesday 27th November 2012
View Replies!

Reverse scroll link - JavaScript Help

I've seen plenty of examples of jQuery scripts that would allow a user to scroll back to the top of the page, but is there anything that could do the reverse\t I have a client who seems to think that who uses his new site doesn't realise that they can in fact scroll DOWN, despite there being a scrollbar...\t:wtf:Anyway, in order to appease the anger of the clients :D, I need a pointer to anything that would say, move the browser down 500px or so with each click. I can't find anything, and JS is not my language. Pointers welcome, I'm sure I could figure something out.Cheers in advance!
VIEWS ON THIS POST

144

Posted on:

Tuesday 27th November 2012
View Replies!

Using link in child window to write to textbox in parent window - JavaScript Help

I am having a struggle with some coding. I have a page where you can open a popup window with a bunch of links on it. I want to be able to click a link and have the information obtained on the link write to a textbox on the parent window. The window needs to stay open so they can click on several links and add a bunch of information to the text box. My current coding for the child window is: while($row = mysql_fetch_array($result)) { echo"
VIEWS ON THIS POST

167

Posted on:

Tuesday 27th November 2012
View Replies!

link help - JavaScript Help

,I have this code to add items into the cart:Add to cartThis adds the item correctly but it takes me into the cart.php page.How should I modified it so it adds the item into the cart and keeps me into my parent pageThank you
VIEWS ON THIS POST

159

Posted on:

Tuesday 27th November 2012
View Replies!

jQuery links problem - JavaScript Help

, I'm having a jQuery problem. I'm trying to create ajax pagination but there is one big flaw. Everything works like it should but the ajax works only one time. Example. I go to the page, click on next (or any of the page numbers or last etc.) it loads the contents with ajax, displays it, everything's fine. But when I click again on some pagination link (next, any of the numbers etc.) it loads the page normal way. and then the it starts all over again, one time the links make ajax call, the other time they wont. Heres the code: $(document).ready(function() { $("#pagination a").click(function(e) { e.preventDefault(); $("#encodes").fadeOut().delay(400); $.ajax({ type: "GET", url: this + "&pagination=true&ajax=true", dataType: "json", success: function(ms) { $("#encodes").empty().append(ms.content); $("#pagination").empty().append(ms.pagination); $("#encodes").fadeIn(); } }); }); }); How do fix this
VIEWS ON THIS POST

123

Posted on:

Tuesday 27th November 2012
View Replies!

changing image src based on hyperlink click - JavaScript Help

HiI have a captcha image, that is generated by a PHP script.Currently the user can change the captcha, by clicking on the image, but I'd like this to be done by clicking on a hyperlink 'Change captcha'My current code is:
VIEWS ON THIS POST

167

Posted on:

Tuesday 27th November 2012
View Replies!

Allow links to open in new window with on/off feature? - JavaScript Help

, could anyone please provide me with a working example of a javascript that detects all of the active urls on the page and opens them in another window but has the option of opening all links normally (without target="_blank"). So someone can click a link to disable links opening in a new window, but on default they will open in a new window. Could you please provide a working example\t
VIEWS ON THIS POST

160

Posted on:

Tuesday 27th November 2012
View Replies!

Javascript help i want to click a link and have text get copied into a textarea - JavaScript Help

i have a php forum and in the posts i have a link to quote the post... when clicked i want javascript to automatically update the textarea called quickreply at the bottom of the page by entering the quote into it. also i want to be able to quote numerous people. So for example if a thread has 10 replies ... you go to reply 1 and press quote it should input reply 1's content in the textarea at the bottom if you then click quote on reply 3 for example it should keep reply 1's text there and on a newline put reply 3 's content.all i know is in the links ill have to have something like onclick='quotePost(".$postcontent.")'Then obviously ill have to have a quotepost javascript function that will get the text and display it in the textarea called quickreply.Can someone show me how to code the quotepost function
VIEWS ON THIS POST

201

Posted on:

Tuesday 27th November 2012
View Replies!

Javascript help i want to click a link and have text get copied into a textarea - JavaScript Help

i have a php forum and in the posts i have a link to quote the post... when clicked i want javascript to automatically update the textarea called quickreply at the bottom of the page by entering the quote into it. also i want to be able to quote numerous people. So for example if a thread has 10 replies ... you go to reply 1 and press quote it should input reply 1's content in the textarea at the bottom if you then click quote on reply 3 for example it should keep reply 1's text there and on a newline put reply 3 's content.all i know is in the links ill have to have something like onclick='quotePost(".$postcontent.")'Then obviously ill have to have a quotepost javascript function that will get the text and display it in the textarea called quickreply.Can someone show me how to code the quotepost function
VIEWS ON THIS POST

158

Posted on:

Tuesday 27th November 2012
View Replies!

question: Javascript link to start another javascript

hi im new to this ive got a question is it possible to link an item to start another javascript possibly with an on click funktion so that the javascript only starts once you click an item on the navigation bar $(document).ready(function(){ $.uiPro({ leftMenu : { 'item1' : { 'label' : 'Item One', , */
VIEWS ON THIS POST

146

Posted on:

Wednesday 28th November 2012
View Replies!