Click here to Skip to main content
       

JavaScript

 
GeneralRe: urdu PinmvpRichard MacCutchan8-Aug-12 21:28 
AnswerRe: urdu PinmemberRahul Rajat Singh22-Aug-12 1:24 
GeneralRe: urdu PinmemberSandip.Nascar22-Aug-12 11:03 
QuestionLooping through elements, to find textbox, and get values Pinmemberjkirkerx8-Aug-12 13:12 
AnswerRe: Looping through elements, to find textbox, and get values Pinmemberjkirkerx8-Aug-12 18:13 
GeneralRe: Looping through elements, to find textbox, and get values PinmemberAndrei Straut9-Aug-12 4:41 
GeneralRe: Looping through elements, to find textbox, and get values Pinmemberjkirkerx9-Aug-12 6:27 
AnswerRe: Looping through elements, to find textbox, and get values PinmemberAndrei Straut9-Aug-12 9:37 
Now, I'm no JavaScript guru, but...
 
if ((nameArray[i] != "") && (codeArray[i] != ""))
Here I would also add a jQuery.trim() on nameArray[i]. You may have values that are simply spaces, and checking for empty string will return false
 
Also, in the for you could dump nameCount and codeCount. Maybe you didn't post the full function, but nameCount is used only for upper bound limit (which could be replaced with parseInt($("._name_Field").length)), and codeCount isn't used at all.
 
Other than that, seems to be fine. Also, it's good that you are commenting your code. I've been through some situations in my (relatively short) career when I banged my hand on a wall for not commenting my code a few months earlier.
 
And if it works for you the way you want it, it's all good. I may get burned for this, but I have a saying:
Make it work. Then do it better
 
Wrapping it all up, the final function would be:
var elements = [];
 
// Create Arrays to hold the values
var nameArray = [];
$("._name_Field").each(function () { nameArray.push($(this).val()) });
 
var codeArray = [];
$("._code_Field").each(function () { codeArray.push($(this).val()) });
 
// Gather the Data from the Element Containers from valid elements
var jdx = 0;
for (i = 0; i <= parseInt($("._name_Field").length) - 1; i++) {
  if ($.trim(nameArray[i]) != ""
	&& $.trim(codeArray[i]) != "") {
     elements[jdx] = [];
     elements[jdx]["name"] = nameArray[i];
     elements[jdx]["code"] = codeArray[i].toUpperCase();
     
     jdx++;
  }
}
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.

GeneralRe: Looping through elements, to find textbox, and get values Pinmemberjkirkerx9-Aug-12 10:18 
GeneralRe: Looping through elements, to find textbox, and get values PinmemberAndrei Straut9-Aug-12 10:35 
AnswerRe: Looping through elements, to find textbox, and get values PinsitebuilderAndy Brummer9-Aug-12 10:26 
GeneralRe: Looping through elements, to find textbox, and get values Pinmemberjkirkerx9-Aug-12 16:54 
GeneralRe: Looping through elements, to find textbox, and get values PinsitebuilderAndy Brummer10-Aug-12 4:56 
GeneralRe: Looping through elements, to find textbox, and get values Pinmemberjkirkerx10-Aug-12 6:31 
QuestionGet value from textbox created with createElement Pinmemberjkirkerx6-Aug-12 15:48 
AnswerRe: Get value from textbox created with createElement PinmemberBobJanova7-Aug-12 0:12 
GeneralRe: Get value from textbox created with createElement Pinmemberjkirkerx7-Aug-12 6:24 
AnswerRe: Get value from textbox created with createElement Pinmembertwseitex7-Aug-12 8:25 
GeneralRe: Get value from textbox created with createElement Pinmemberjkirkerx8-Aug-12 10:54 
Questionadapt datatable jquery to jee application Pinmemberahmadiss4-Aug-12 23:34 
AnswerRe: adapt datatable jquery to jee application PinmvpRichard MacCutchan5-Aug-12 1:24 
Questionshowmodaldialog return value undefined across domain PinmemberAmr M. K.4-Aug-12 23:24 
AnswerRe: showmodaldialog return value undefined across domain Pinmemberjkirkerx5-Aug-12 11:05 
GeneralRe: showmodaldialog return value undefined across domain PinmemberAmr M. K.6-Aug-12 22:05 
AnswerRe: showmodaldialog return value undefined across domain PinmemberBobJanova5-Aug-12 23:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web04 | 2.8.140718.1 | Last Updated 19 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid