Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
127
rated 0 times [  131] [ 4]  / answers: 1 / hits: 24961  / 12 Years ago, fri, june 15, 2012, 12:00:00
    function getDbValue()
{
alert($('[data-bind]').length);
alert($('[data-bind][0].data-bind'));
alert($('[data-bind][0].value'));
jQuery.each($('[data-bind]'), function(databind,key)
{
alert(key);
alert(databind);
alert(databind[key].data-bind);
})

}


The above is my function and i want to read all inputs that have the properties data-bind within them for example



<input type=text id=frmIn1-Officer data-bind=value: AOfficer class=InputText/>


^ When running my function i would want it to return 'AOfficer' as that is the data-bind value.



So an example is



<input type=text id=frmIn1-Officer data-bind=value: AOfficer1 class=InputText/>
<input type=text id=frmIn1-Officer data-bind=value: AOfficer2 class=InputText/>
<input type=text id=frmIn1-Officer data-bind=value: AOfficer3 class=InputText/>
<input type=text id=frmIn1-Officer data-bind=value: AOfficer4 class=InputText/>
<input type=text id=frmIn1-Officer data-bind=value: AOfficer5 class=InputText/>
<input type=text id=frmIn1-Officer data-bind=value: AOfficer6 class=InputText/>


And in the for each loop i would like to be able to use the value of data bind..
e.g values[0] = 'AOfficer1'



Sorry if my explanation is slightly confusing, i have the idea in my head perfect but trying to put it in writing is alot harder.


More From » jquery

 Answers
53

jQuery interprets the data-something attributes differently than other attributes. So you should select all your elements and look for their data bindings like this:



$(document).ready(function(){
$('input.InputText').each(function(){
var input = $(this);
if ($(input).data().bind) {
alert($(input).data().bind);
}
});
});​


Then you can do string manipulation to parse out your values, I'd suggest using JSON and just loading it in like an object. Here's a working fiddle: http://jsfiddle.net/3NERK/6/


[#84874] Thursday, June 14, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jenamackennac

Total Points: 304
Total Questions: 110
Total Answers: 107

Location: Ecuador
Member since Thu, Jun 4, 2020
4 Years ago
jenamackennac questions
Fri, Feb 18, 22, 00:00, 2 Years ago
Wed, Apr 21, 21, 00:00, 3 Years ago
Thu, Apr 1, 21, 00:00, 3 Years ago
Tue, Feb 2, 21, 00:00, 3 Years ago
;