Friday, 15 July 2011

jQuery form narrow down an array input selection -


I currently have a form that has prepared dynamically generated inputs. Everything I want to do is get input of a certain array index and some work continues to be done (verification and etc.).

Now, I know that I can select input like this:

  var id = $ ('# hiddenInputContainer'). ('[Name =' item [1] [id] "] 'var name = $ (' # hiddenInputContainer ').' [Name =" item [1] [name] "] '); // ..   

But I'm thinking that it is possible to narrow the search of input in [name ^ = 'item [1]'] and then ID and name .

In my case hidden input container will have lots of input and I like JavaScript as much as possible How do I limit the list?

P.S. I Have tried var inputs = $ ('# hiddenInputContainer'). ('[Name = "item [1]"]') and later inputs.find ('[name * = "Id"] ')') , but does it work for some reason?

Example looks like HTML:

  & lt; Input id = "hidden" name = "item [1] [id]" value = "1" /> input type = "hidden" name id = "hiddenInputContainer" & gt; = "Item [1] [name]" value = "one name for item 1" /> input type = "hidden" name = "item [2] [id]" value = "2" /> & Lt; Input type = "hidden" name = "item [2] [name]" value = "one name for item 2" /> & Lt; Input type = "hidden" name = "item [3] [id]" value = "51" /> & Lt; Input type = "hidden" name = "item [3] [name]" value = "one name for item 51" /> & Lt; / Div & gt;    

I think you are trying to do something like this -

  var inputs = $ ('# hiddenInputContainer'). Search ('[name =' item '[1] "]'); Inputs.filter ('' [name * = "id"] ')    

No comments:

Post a Comment