473,320 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Looping through form elements

Hey,

I'm in the process of writing a function to check each element of a
form isn't empty. I've come to a dead end..

Here is my function:
function validateData(){

var i;

var form = document.forms[0];

var formElem = form.elements;

for(i = 0; i < formElem.length; i++){

if(formElem[i].value == ""){

alert('you have not fill out the form');
break;

}else if(formElem[i].value != ""){

continue;

}

formElem[i].focus();

}

}

Any help would be much appreciated :)

Sep 22 '06 #1
2 1894
sorry this is the my amended function that needs scrutinised:

function validateData(){
var i;
var form = document.forms[0];
var formElem = form.elements;
for(i = 0; i < formElem.length; i++){
if(formElem[i].value == ""){
alert('you have not fill out the form');
break;
}else if(formElem[i].value != ""){
continue;
}
}
formElem[i].focus();
}

:)

Sep 22 '06 #2
I removed else clause and moved up the focus() just before the loop
breaks and now it works!

Thank you for the advice :)

Sep 23 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David | last post by:
Hello. I am looking for advice on what is "best practice" regarding looping through a form to check its checkboxes and associated data fields. Here is what I am trying to do (Here is the page...
4
by: blueey | last post by:
I have a span element somewhere somewhere in between my table. How do i loop through the elemenst (namely in this case radio and text) and retreive the values of the child elements and it's type....
27
by: Mike P | last post by:
I will be passing my function a two dimensional array of varying length. Within that array is one data point, and the number of times it should loop through. So, for example, I might pass this...
1
by: Aemca | last post by:
In good old asp you could easily loop through all the elements in a posted form. In a for each loop using the request.form elements. How do I go about this in asp.net? Or should I just specify...
7
by: linq936 | last post by:
Hi, The following is a psudo code to describe my question: vector<int> ints; vector<int>::iterator itr; while (itr != ints.end()){ int j = some_function(*i); if (j>0){ ints.push_back(j); }
1
by: Mel | last post by:
I need to loop through all form elements such as text, radios, check boxes and the like and to save their state in a file. does anyone have JS code to do this ? It can help a bunch thanks
3
by: David | last post by:
Hi, I have an asp page which lists records out in rows Each record has a checkbox with a value parameter equal to the RecordID When the form is run, it goes to a page which I am trying to...
5
by: alanb | last post by:
Hi, hope someone can help, I need to be able to keep a running total of radio buttons selected, as a user goes through a set of 16 questions, devided in to 4 catorgories, then on "submit" have the...
3
by: SAM | last post by:
ll a écrit : <script type="text/javascript"> function checkform( f ) // f is the form to check { var txt1 = 'Please make a selection for the Learning Outcome :', txt2 = '\nYour...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.