jquery get the value of a select box
make the select box or input box into a $jq object first, then
use $jquery_object.val().
http://api.jquery.com/val/
console.log(product_text_color.val());
console.log(button_text_color.val());
changeProductTextColor({'color': product_text_color.val()}, '2');
changeTextColor({'color': button_text_color.val()},'install','2');
Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts
Saturday, November 3, 2012
using jscolor programatically (no jquery)
jscolor is a color picker javascript
it lets u make an input type="text" into a color picker, just by adding the class .color to the <input tag>
1
it inside a function
(the input tag element, referenced as this) is an OBJECT with property .color which is the chosen color in the colorpicker
2
therefore, you can pass
product_text_color.attr('class', 'color'); // the input box has been made into a jquery object first
// attach color picker to it by adding a class .color to it
{'color': product_text_color.val()}
programatically passing an OBJECT with prop .color to a function:
since you can't directly get the colorpicker, USE JQUERY TO DO IT, and this is the way how.
and then the fn taking this OBJECT as arg, references it like this: colorObj.color
Refer to next post:
jquery get the value of a select box
it lets u make an input type="text" into a color picker, just by adding the class .color to the <input tag>
1
it inside a function
(the input tag element, referenced as this) is an OBJECT with property .color which is the chosen color in the colorpicker
2
therefore, you can pass
product_text_color.attr('class', 'color'); // the input box has been made into a jquery object first
// attach color picker to it by adding a class .color to it
{'color': product_text_color.val()}
programatically passing an OBJECT with prop .color to a function:
since you can't directly get the colorpicker, USE JQUERY TO DO IT, and this is the way how.
and then the fn taking this OBJECT as arg, references it like this: colorObj.color
Refer to next post:
jquery get the value of a select box
concatenating strings in javascript
concatenating strings in javascript
http://www.quirksmode.org/js/strings.html
http://www.quirksmode.org/js/strings.html
You can even use numbers or calculations, like:
document.write (a + 3*3 + b);
Now we concatenate string
a, then the result of 3*3, treated as a string for the occasion, and then b, which givesHello world!9I am a JavaScript hacker.
Watch out if you want to add numbers. This
document.write (a + 3+3 + b);
concatenates four strings:
a, 3, 3 and b, because + in this context meansconcatenate strings, not add, and givesHello world!33I am a JavaScript hacker.
Use brackets if you want to add 3 and 3 before making the string.
document.write (a + (3+3) + b);
concatenates
a, the result of 3+3 and b and givesHello world!6I am a JavaScript hacker.
indexOf
One of the most widely used automatical methods is
indexOf. Each character has an index number, giving its position in the string. Note that the first character has index 0, the second one index 1 etc. So the index of 'w' in string a is 6.
Using
indexOf we can read out the index number of a character. Put the.indexOf('') behind the string name and put the character you're looking for between the quotes. Thisvar a = 'Hello world!';
document.write(a.indexOf('w'))
gives
6. If the same character occurs more than once, this method gives the first occurrence. SoCheatSheet for Javascript language finer points, for-loop in Javascript
finer points, ...or indeed what you should know about the JavaScript Language right from the start, even.
http://bonsaiden.github.com/JavaScript-Garden/
Read when you have time, and want some leisure reading.
Learnt this, today:
http://bonsaiden.github.com/JavaScript-Garden/
Javascript Cheatsheet website
xxx();
function xxx() { //this function will fly to the top, document scope,
//even if function call is before this fn definition, still works.
}
var xxx = function () {} // if the fn call is before this fn def, will errormsg: xxx is 'undefined'
for namespacing purpose, function is the only struct that limits scope of its internal variables:
var Bill = {
xxx : function () {
// only function are scope boundary
// ...but only fly to here.
function aaa() {
// so this function aaa() won't be able to fly to the top...
}
(var x;)
for (a=0;a<2;a++) {
var x = 123; // this var will fly out of this for loop, as if belonging to
//the function xxx's scope. (as if declared as above line in parentheses)
}
}
}
Bill.xxx()
Q. why need to wrap in $() the whole block?
how to iterate over a list in javascript
http://ajaxian.com/archives/how-many-ways-can-you-iterate-over-an-array-in-javascript
THE CANONICAL WAY:
http://forums.asp.net/t/1040956.aspx/1
for(var i = 0; i < YourList.length; i++)
{
var yourObject = YourList[i];
//Do whatever you want.
}
http://www.openjs.com/articles/for_loop.php
http://bonsaiden.github.com/JavaScript-Garden/
Read when you have time, and want some leisure reading.
Learnt this, today:
http://bonsaiden.github.com/JavaScript-Garden/
Javascript Cheatsheet website
xxx();
function xxx() { //this function will fly to the top, document scope,
//even if function call is before this fn definition, still works.
}
var xxx = function () {} // if the fn call is before this fn def, will errormsg: xxx is 'undefined'
for namespacing purpose, function is the only struct that limits scope of its internal variables:
var Bill = {
xxx : function () {
// only function are scope boundary
// ...but only fly to here.
function aaa() {
// so this function aaa() won't be able to fly to the top...
}
(var x;)
for (a=0;a<2;a++) {
var x = 123; // this var will fly out of this for loop, as if belonging to
//the function xxx's scope. (as if declared as above line in parentheses)
}
}
}
Bill.xxx()
Q. why need to wrap in $() the whole block?
how to iterate over a list in javascript
http://ajaxian.com/archives/how-many-ways-can-you-iterate-over-an-array-in-javascript
THE CANONICAL WAY:
http://forums.asp.net/t/1040956.aspx/1
for(var i = 0; i < YourList.length; i++)
{
var yourObject = YourList[i];
//Do whatever you want.
}
http://www.openjs.com/articles/for_loop.php
More Optimized
var len=arr.length;
for(var i=0; i<len; i++) {
var value = arr[i];
alert(i =") "+value);
}
Thursday, November 1, 2012
How to join strings, format strings... add variables to strings... printf?
Javascript dynamic string manipulation.
How to join strings, format strings... add variables to strings... printf?
It has nothing as neat as Python's... but you'll find a way when you need to.
Wednesday, September 26, 2012
jslint javascript validator for IE7
No trailing ',' comma, don't miss out any closing ';' semicolons to write IE7-compatible javascript
else js execution just STOPs at those places with error.
IE7 javascript validator
http://www.jslint.com/
else js execution just STOPs at those places with error.
IE7 javascript validator
http://www.jslint.com/
Subscribe to:
Posts (Atom)