Check equality in 'else' in 'if – else' statement

Say we have such code (js): /** * @param {String} type Could be only ‘high’ or ‘low’ * @return {String} */ function getSome(type) { if (type == ‘high’) { return ‘This is high’; } else if (type == ‘low’) { return ‘This is low’; } } If this variant preferable than this (I do not […]

jQuery checkbox to enable/disable text input and add/remove default value

I am trying to create a small reusable function that will, when checked, disable a text field and insert a default value of ‘160’, and when unchecked, enable the field and remove the value. I have it mostly finished but the unchecking part is throwing me off. $(‘#chkIsTeamLead’).change(function(){ if ($(‘#chkIsTeamLead’).checked = true){ $(‘#txtNumHours’).val(‘160’).attr(‘disabled’, ‘disabled’); console.log(‘checked’); […]

Change logo image based on screen resolution of the browser

I have two images, one with the logo in black and one with the logo in white. I would like to have the white logo when the browser is less than 768px width and black logo when it’s bigger. I tried something but is not changing in real time, only if I reload the page. […]

Why doesn't this return the price?

just wondering how to return the price? This simply returns the whole function? var amount = 0; var price = 99.99; var tax = 10; var balance = 550; function calculateTax() { var prices = price + tax; return prices; }; calculateTax(); console.log(calculateTax); Thanks

Regex and JavaScript String With a Dollar ($) at the end

In answering this PHP question: regex – preg_replace string, I came across something in Javascript I didn’t understand. Given the following: var s = “abc1!?d$”; alert(s.replace(/\W+/, ” “)); I am alerted: abc d$ Why is it not stripping out the last dollar?

How to Create Multilevel jquery accordion menu using jQuery?

I want to create multilevel accordion Navigation using jQuery , I tried using this script but it not allow the multi-level. Please view the Image what exactly I am looking for, http://www.i-marco.nl/weblog/jquery-accordion-menu/# alt text http://img36.imageshack.us/img36/7897/multilevelaccordian.png Thanks

Regular expression to match “snnnoooowww” to “snow”

I am trying to write a regular expression that will match any number of a certain character within a certain order of characters. In example: “ssssnnnowww” would match to “snow” but “sssnnnsssooooowwww” would not match to “snow” I have tried the following: /[s][n][o][w]/g // no luck /s*n*o*w*/ // no luck

Deleting empty spaces in a string

Okay I have a simple Javascript problem, and I hope some of you are eager to help me. I realize it’s not very difficult but I’ve been working whole day and just can’t get my head around it. Here it goes: I have a sentence in a Textfield form and I need to reprint the […]

Calculating difference between username and email in javascript

for security reasons i want the users on my website not to be able to register a username that resembles their email adress. Someone with email adress user@domain.com cant register as user or us.er, etc For example i want this not to be possible: tester -> tester@mydomain.com (wrong) tes.ter -> tester@mydomain.com (wrong) etc. But i […]

How to show/hide a div on mouseover?

Possible Duplicate: How to show/hide a div on mouseover using jquery? I have a div like this: <div id=”parent”> foo <div id=”child” style=”display:none;”> hidden </div> </div> I want to have the child div shown whenever someone moves their mouse over the parent div, and when he moves his mouse away, to hide the parent div. […]