modernlife
10-30-2003, 08:55 PM
Here's an interesting one:
Say you have a form with names go like this:
<input type="text" name="madonna_song_name">
<input type="text" name="britney_song_name">
<input type="text" name="madonna_age">
<input type="text" name="britney_age">
You might access the form objects like this:
document.form[0].madonna_song_name.value = "blah";
document.form[0].britney_age.disabled = true;
etc.
Now, let's say you were passing the value "madonna" to a function that is trying to disable/enable all the form inputs for that singer:
enable_disable( madonna );
function enable_disable( singer ) {
// singer == "madonna";
// go through form values:
// document.form[0].<singer>_song_name.disabled = true;
// document.form[0].<singer>_age.disbalbed = true;
}
My question is, how do you get the "<singer>" part to be dynamic? I tried things like:
testing = singer . "_song_name";
document.form[0].'testing'.disabled = true;
etc.
But I can't seem to get the syntax right.
Please point this sorry newb in the right direction, thanks! :)
Say you have a form with names go like this:
<input type="text" name="madonna_song_name">
<input type="text" name="britney_song_name">
<input type="text" name="madonna_age">
<input type="text" name="britney_age">
You might access the form objects like this:
document.form[0].madonna_song_name.value = "blah";
document.form[0].britney_age.disabled = true;
etc.
Now, let's say you were passing the value "madonna" to a function that is trying to disable/enable all the form inputs for that singer:
enable_disable( madonna );
function enable_disable( singer ) {
// singer == "madonna";
// go through form values:
// document.form[0].<singer>_song_name.disabled = true;
// document.form[0].<singer>_age.disbalbed = true;
}
My question is, how do you get the "<singer>" part to be dynamic? I tried things like:
testing = singer . "_song_name";
document.form[0].'testing'.disabled = true;
etc.
But I can't seem to get the syntax right.
Please point this sorry newb in the right direction, thanks! :)