Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dissecting an array into array help

Status
Not open for further replies.

CompOp

Technical User
Jan 2, 2011
8
AU
Hi, thank you for looking at this post.

I am trying to make my form validation more dynamic, I have never tried to take elements from one array befor and place them in another to be read back to the browser. I am still kinda new to this although I do have an ok grasp on php still noobie at that to I guess, I have seen a similiar thing accomplished in php, however I would like to accomplish my form validation on client side (the way it should be).

2. var Element=new Array("mytext","mytext1","mytext2");
3. var BadData=new Array();
4. var i=0;
5. var v=0;
6. while (i<=2)
7. {
8. var myTextField = document.getElementById("Element");
9. if (myTextField.value.length == 0)
10. {
11. BadData[v]=Ellement;
12. i++;
13. v++;
14. }
15. else
16. {
17. i++;
18. }
19. }

The problem is on line 9 char 2 I keep getting an error of object required. Im kinda stuck on this any help would be appriciated. Please let me know if I have not givenen enough information.
 
Your issues stem from here:

Code:
var myTextField = document.getElementById("Element[i]");

What you are saying here is get the element with an id that is the literal string "Element" But I doubt you have an element in your page with an ID like:
Code:
<input type="text" id="Element[i]">

Since what I assume you want is to make it grab your element IDs from your original array, you need pass the array as such and not as a literal string. Remove your quotes around Element in your getElementById call.
Code:
var myTextField = document.getElementById([red]Element[i][/red]);


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
sweet that kinda fixed it script works, not the results i was hopping for but atleast it works.
Results of the script runing are:
please fill in the following feildsElementElementElement

which the desired results I was hoping for was supposed to be:
please fill in the following feildstexttext1text2.

Its all good though I think I know where I went wrong, used regular when I should have used premium... or maybe I should be reading the "element" array into a veriable prior to adding it to the "baddata" array.

Vacunita or phil I am much appriciative of your help with this I would have been lost without it. Many thanx.

 
Probably the extra L in your variable here:

Code:
BadData[v]=El[red]l[/red]ement[i];

Should be only one L as per your variable.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top