Close a div when clicked anywhere on page

I have a search box that selects users and sends them into a div on my page which obviously opens with the script. But I would like the box to close if the user clicks outside of the div anywhere on my sites page. I’ve played around with a few ideas but haven’t got what […]

Why did I get [object HTMLParagraphElement]

I am a newbie. Here is my code: <html> <head> <script type=”text/javascript”> function replyOne () { document.getElementById(“comment_content”).value = document.getElementById(“username”) } </script> </head> <body> <p id=”username”>Jack</p> <textarea id=”comment_content” ></textarea> <button onclick=”replyOne()”>Copy Text</button> </body> </html> I expect that when I click the button, it will copy ‘Jack’ to the textarea. But instead it just writes ‘[object HTMLParagraphElement]’.

Return specific part of string in Javascript

I would like to manipulate this following string: 20_hbeu50272359_402_21 so that I am left with only hbeu50272359 is there a way to how could I delete those outer numbers? Not sure how to go about it. The strings may also take this format: hbeu50272359_402_21

dojo tutorial: dojo is not defined

I want to get startet with dojo. Therefore I am useing their tutorials: http://dojotoolkit.org/documentation/tutorials/1.8/hello_dojo/ The simplest tutorial displays this page <!DOCTYPE html> <html> <head> <meta charset=”utf-8″> <title>Tutorial: Hello Dojo!</title> </head> <body> <h1 id=”greeting”>Hello</h1> <!– load Dojo –> <script src=”//ajax.googleapis.com/ajax/libs/dojo/1.8.1/dojo/dojo.js” data-dojo-config=”async: true”></script> </body> </html> I now open the page (tried both localy and hosted version on […]

KnockoutJS setting focus after adding to array/collection

I have viewmodel with an array of diagnosis codes. In my html I have a button data-bound to a click that adds a blank diagnosis code to the array. This all works. What I cant figure out, is how to set focus to the dynamically added textbox when a code is added. What can I […]

Is this JavaScript optimization or not?

Can someone explain me what are the differences between those two functions below? I’m wondering if JavaScript engines do some kind of nano-optimizations here. function withoutVar() { return ‘stackoverflow’; } function withVar() { var result = ‘stackoverflow’; return result; } var a = withoutVar(); var b = withVar();

A function inside a for loop with jQuery and Javascript

i have the following code : $(document).ready(function () { for (i = 1; i <= number_of_banners; i++) { var selector = “#link_” + i; $(selector).click(function () { alert(i); }); } }); but the alert() can’t get the “i” variable from the for loop. How can I use the i variable of for loop inside the […]

calling function without brackets in JavaScript

This question already has an answer here: What is the difference between a function call and function reference? 6 answers

Reset radio button using jQuery

I’m have multiple radio button. After check or select radio button value randomly, i need to reset radio button to default checked or selected value on button click. My HTML code is below. jQuery function ResetRdo() { // Code to reset ? } HTML <table> <tr> <td> <input type=”radio” name=”rdo1″ value=”a” checked=”checked” /> A <input […]

input returns true on an empty input

I can’t get my head around this issue! I have simple jquery validation on button click to validate if the input field is empty. http://fiddle.jshell.net/fyxP8/3/ I have no idea why the input filed returns with value not empty when it is empty. Any help is very much appreciated