Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-05-2013, 08:29 AM   PM User | #1
xekon
New to the CF scene

 
Join Date: Feb 2013
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
xekon is an unknown quantity at this point
Question input text box javascript function call without ID name possible or anyway overload?

Right now spectrum gets called for the input box showInputAndInitial through docs.js function that is labled $("#showInputAndInitial").spectrum()

my question is can I use just the one function in docs.js or do I need to make a new function entry for every single input box, My page will have somewhere around 25 input boxes, so I was hoping there was a more efficient method than just making a ton of entries in docs.js (anyway to not use the id name to call the function?):

$("#showInputAndInitial").spectrum()
$("#showInputAndInitial2").spectrum()
$("#showInputAndInitial3").spectrum()
......

example of php page:
Code:
<link rel="stylesheet" type="text/css" href="css/default.css">
<link rel="stylesheet" type="text/css" href="css/spectrum.css">

<script type="text/javascript" src="js/jquery-1.8.3.js"></script>
<script type="text/javascript" src="js/spectrum.js"></script>
<script type='text/javascript' src='js/docs.js'></script>

<input type='text' name='showInputAndInitial' id='showInputAndInitial' value='daa520' />

<input type='text' name='showInputAndInitial2' id='showInputAndInitial2' value='daa520' />

<input type='text' name='showInputAndInitial3' id='showInputAndInitial3' value='daa520' />

<input type='text' name='showInputAndInitial4' id='showInputAndInitial4' value='daa520' />

<input type='text' name='showInputAndInitial5' id='showInputAndInitial5' value='daa520' />
docs.js:
Code:
$(function() {
	$("#showInputAndInitial").spectrum({
		preferredFormat: "hex",
		showPalette: true,
		showSelectionPalette: true,
		palette: [ ],
		localStorageKey: "jitest.homepage", // Any Spectrum with same string will share
		showInitial: true,
		showInput: true
	});
});

Last edited by xekon; 02-06-2013 at 12:20 AM..
xekon is offline   Reply With Quote
Old 02-05-2013, 12:08 PM   PM User | #2
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,469
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
$("input[type=text][name][value][id]") will hit only text inputs with name, ID, and value attribs: most likely the droids you are looking for. use a wrapping container with an ID if you need to be more specific.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
xekon (02-06-2013)
Reply

Bookmarks

Tags
function, input, input id, overload, spectrum

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:17 PM.


Advertisement
Log in to turn off these ads.