Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,371
    Thanks
    11
    Thanked 591 Times in 572 Posts
    $("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 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • Users who have thanked rnd me for this post:

    xekon (02-06-2013)


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •