R
Randell D.
Folks,
I can program fairly comfortably in PHP and can, for the most part using
these skills and others that I've picked up over the years manage to
read/understand most code in Javascript... so I'm just asking for a few
pointers (or the full solution if you have the time) for what I want to do.
Basically, I want to write a javascript wherby I only need to pass it the
names of form fields - then my javascript will check each form field has a
value greater than zero in length - Any field value that fails this test is
noted... when all fields have been tested, an alert box opens telling the
user that they forgot to fill in 'x' number of fields and the field names
are named as they would appear visably on the form. I can write most of the
script but there is a method that I would like to do but don't know how to
implement it in Javascript...
A brief example of a form field would be the following HTML:
Street Name: <input type=text size=30 name=streetName>
My solution to alert the user in a user friendly manner would be to have an
array with string indices. Thus the following piece of javascript:
var requiredfields=new Array();
requiredfields['streetName']="Street Name";
The reason why I have it setup like this is I can use the index of an
element to check a specific field in a form. If that field string length is
zero, then the alert box will report "Street Name" and not "streetName"...
My question is: How can I create a loop that will give me the element name?
In PHP I could do something like :
foreach($requiredFields as $inputTagName=>$realFieldName)
{ print("<br>Input tag $inputTagName is known by the user as
$realFieldName"); }
How can I achieve this in Javascript? How can I loop thru a string indexed
array? It does not have to be a for loop... but I do want to have the real
value of the array element, and the array element value...
Can anybody help me out? I'm still playing with the rest of my scrpit - I'm
confident that I can do the rest...
Thanks in advance, replies please via the newsgroup... it might help someone
else...
randell d.
I can program fairly comfortably in PHP and can, for the most part using
these skills and others that I've picked up over the years manage to
read/understand most code in Javascript... so I'm just asking for a few
pointers (or the full solution if you have the time) for what I want to do.
Basically, I want to write a javascript wherby I only need to pass it the
names of form fields - then my javascript will check each form field has a
value greater than zero in length - Any field value that fails this test is
noted... when all fields have been tested, an alert box opens telling the
user that they forgot to fill in 'x' number of fields and the field names
are named as they would appear visably on the form. I can write most of the
script but there is a method that I would like to do but don't know how to
implement it in Javascript...
A brief example of a form field would be the following HTML:
Street Name: <input type=text size=30 name=streetName>
My solution to alert the user in a user friendly manner would be to have an
array with string indices. Thus the following piece of javascript:
var requiredfields=new Array();
requiredfields['streetName']="Street Name";
The reason why I have it setup like this is I can use the index of an
element to check a specific field in a form. If that field string length is
zero, then the alert box will report "Street Name" and not "streetName"...
My question is: How can I create a loop that will give me the element name?
In PHP I could do something like :
foreach($requiredFields as $inputTagName=>$realFieldName)
{ print("<br>Input tag $inputTagName is known by the user as
$realFieldName"); }
How can I achieve this in Javascript? How can I loop thru a string indexed
array? It does not have to be a for loop... but I do want to have the real
value of the array element, and the array element value...
Can anybody help me out? I'm still playing with the rest of my scrpit - I'm
confident that I can do the rest...
Thanks in advance, replies please via the newsgroup... it might help someone
else...
randell d.