Dear Experts,
I am following Mr.Steve Sanderson Example for working with variable length list, ASP.NET MVC 2-style.
In my Scenario I have one text box in which a user scan through a barcode scanner and the value of scanned barcode will distributed in variable list input fields.
I am using JQuery to set Values of those generated fields,
Example of dynamically Generated DIV is
<div class="editorRow">
<input type="hidden" name="gifts.index" autocomplete="off" value="a041d40e-d016-4543-b3f1-bf72239e1377" />
Area Code <input id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__AreaCode" name="gifts[a041d40e-d016-4543-b3f1-bf72239e1377].AreaCode" type="text" value="0" />
Account No: <input id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__ConsCode" name="gifts[a041d40e-d016-4543-b3f1-bf72239e1377].ConsCode" type="text" value="0" />
Amount: <input id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__CAmount" name="gifts[a041d40e-d016-4543-b3f1-bf72239e1377].CAmount" type="text" value="0" />
Coll No: <input Value="1" id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__CollNo" name="gifts[a041d40e-d016-4543-b3f1-bf72239e1377].CollNo" type="text" value="1" />
<a href="#" class="deleteRow">delete</a>
<span class="field-validation-valid" id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__AreaCode_validationMessage"></span>
<span class="field-validation-valid" id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__ConsCode_validationMessage"></span>
<span class="field-validation-valid" id="gifts_a041d40e-d016-4543-b3f1-bf72239e1377__CAmount_validationMessage"></span>
if you see there is one hidden field having index and value=”a041d40e-d016-4543-b3f1-bf72239e1377″ which is common in other members with their names. When I add one more DIV the hidden input value again change and all members of that div having the same common value.
I am stuck how to deal with it, so far I have successfully distributed the value of scan barcode to the input boxes which are out side of that dynamic DIVs like:
$("#ScanBCode").keyup(function (e) {
barCode = $("#ScanBCode").val();
if (barCode.length == 21) {
var count = 1;
Checking(count);
}
function Checking(count) {
var code = barCode.substr(2, 3);
var ACode = barCode.substr(5, 3);
var Ccode = barCode.substr(8, 5);
var Amount = barCode.substr(13, 8) / 1000;
$("#TabACode").val(ACode);
$("#TabCCode").val(Ccode);
$("#TabAmount").val(Amount);
$("#TabCollNo").val(code);
$("#ScanBCode").val("");
}
});
Any Idea
not sure wheter i got this one right, but it seems you’re looking for a way to loop over a jquery collection, which can be done using jQuery.each.
so instead of watching out for some generated IDs on your input field, i’d recommend looping over all of your generated ‘fields’, itentified by their class
editorRow. just note that instead of having a separate id for each input field, you’d have to set some class on them, for example:now you can apply the following javascript inside of your
keyuphandler:just post back in case something isn’t clear here.