C
Chuck Anderson
I'm pretty much a JavaScript novice. I'm good at learning by example
and changing those examples to suit my needs. That said ....
..... I have some select fields in a form I created for a database search
that I am unable to figure out how to access. (The search is
implemented in Php/MySQL.)
The user enters search values for: name, address1, city, .... etc.,
..... and for each of these they also select whether the search should
look for the field to be equal to, not equal to, Like, or Not Like the
value in the database.
So in the form I have:
<input type=text name=city>
in combination with
<select name=func[city]>
<option value='='>=</option>
<option value='!='>!=</option>
<option value='LIKE'>LIKE</option>
<option value='!='NOT LIKE>NOT LIKE</option>
</select>
For an example, this search could be to find an entry "WHERE city
$func[city]] $city. (Php - e.g., WHERE city = 'Denver'). This works
fine - in Php. I use similar combinations for name, address, etc., ...
Okay, here's the JavaScript problem. For the Reset action I have a
JavaScript function to Reset all the form fields. I want to Reset the
selected indexes for the "func" fields (func[name], func[city],
func[state], ...) using a loop that goes through the associative array,
"func." I cannot find the right syntax to address them as an array and
I am beginning to think that JavaScript does not see them as an array.
I could have just as well named them func_name, func_address, func_city,
..... (??)
I have already come up with a workaround. I loop though *every* form
element and if substring(0,5) = 'func[' I set the SelectedIndex for that
element to 0.
What I would like is a definitive answer. Am I correct that JavaScript
does not see func as an array, or is there a syntax for accessing it
that has so far totally eluded me.
I can access individual members of func like so:
alert (form["func[host_id]"].selectedIndex);
and that works, but I cannot figure out the correct syntax to loop
through the array with:
for (x in form.func)
Is it simply not possible? If it is possible, what is the correct
syntax for::
// within a function where form is an input = document.theform
for (x in form.func) // I also tried for (x in form["func"])
{
alert (x);
form.func[x].SelectedIndex = 0;
}
I put the alert in that loop for testing and it never seems to even
enter the loop.
Can this be done the way I want to do it?
Thanks in Advance for any help.
and changing those examples to suit my needs. That said ....
..... I have some select fields in a form I created for a database search
that I am unable to figure out how to access. (The search is
implemented in Php/MySQL.)
The user enters search values for: name, address1, city, .... etc.,
..... and for each of these they also select whether the search should
look for the field to be equal to, not equal to, Like, or Not Like the
value in the database.
So in the form I have:
<input type=text name=city>
in combination with
<select name=func[city]>
<option value='='>=</option>
<option value='!='>!=</option>
<option value='LIKE'>LIKE</option>
<option value='!='NOT LIKE>NOT LIKE</option>
</select>
For an example, this search could be to find an entry "WHERE city
$func[city]] $city. (Php - e.g., WHERE city = 'Denver'). This works
fine - in Php. I use similar combinations for name, address, etc., ...
Okay, here's the JavaScript problem. For the Reset action I have a
JavaScript function to Reset all the form fields. I want to Reset the
selected indexes for the "func" fields (func[name], func[city],
func[state], ...) using a loop that goes through the associative array,
"func." I cannot find the right syntax to address them as an array and
I am beginning to think that JavaScript does not see them as an array.
I could have just as well named them func_name, func_address, func_city,
..... (??)
I have already come up with a workaround. I loop though *every* form
element and if substring(0,5) = 'func[' I set the SelectedIndex for that
element to 0.
What I would like is a definitive answer. Am I correct that JavaScript
does not see func as an array, or is there a syntax for accessing it
that has so far totally eluded me.
I can access individual members of func like so:
alert (form["func[host_id]"].selectedIndex);
and that works, but I cannot figure out the correct syntax to loop
through the array with:
for (x in form.func)
Is it simply not possible? If it is possible, what is the correct
syntax for::
// within a function where form is an input = document.theform
for (x in form.func) // I also tried for (x in form["func"])
{
alert (x);
form.func[x].SelectedIndex = 0;
}
I put the alert in that loop for testing and it never seems to even
enter the loop.
Can this be done the way I want to do it?
Thanks in Advance for any help.