-6

this is about foreach function in JavaScript/jQuery.

I would like some help with wildcard of an input name

example: when any of the inputs' names that starts with 'field_{something}' are clicked.

Amged
  • 39
  • 5
  • 2
    There is no question here. This is pseudocode at best, not jQuery. [What have you tried?](http://whathaveyoutried.com) – Matt Ball Sep 05 '12 at 20:45
  • Matt, If i knew the code of jQ i wouldn't post here ... i posted the code the way i know it which is pseudocode...anyways @dotsamuelswan answered my question, thanks – Amged Sep 05 '12 at 20:57

2 Answers2

2

Your question isn't very well formatted, but it kind of sounds like you're looking for a wildcard selector.

$("[name^=field_]").click(function() {
  //do stuff
});

More at this SO thread.

Community
  • 1
  • 1
samuelesque
  • 1,165
  • 13
  • 30
  • exactly wildcard selector .. any field that has the name of 'field_{something}' – Amged Sep 05 '12 at 20:49
  • Above is the syntax for a wildcard selector. I would consider using either class or id as opposed to name. – samuelesque Sep 05 '12 at 20:54
  • Actually I can't use class, as html output of the inputs is made through a php class that is iOnCube encoded. which is why I can't add class to it. it only adds #IDs – Amged Sep 05 '12 at 21:08
1
$("input[name^=field_]").each(function(){
 var currentInput = this;
 //...do something ...  
 });
WojtekT
  • 4,735
  • 25
  • 37