D
David
Hi group,
I'm trying to add a very light sprinkling of JavaScript to a web form as
follows:
0. Of most importance, to me, at least, is that the form must not
_require_ JavaScript in order to function, so this little sprinking is
to be a 'progressive enhancement' only.
1. One input which the user must make on the form is to select 1 of 3
radio buttons to indicate a particular choice.
2. If a particular one of the radio buttons is *not* the selected button
(either at the time the form loads, having read in the user's existing
stored preference data, or as a result of the user selecting 1 of the
other 2 radio buttons), a text input field beneath the radio buttons
should be shown as 'disabled'.
(The "magic" button is the 2nd of 3 in the code below.)
2a. If the user has no existing stored data, then the "magic" radio
button clearly has not already been selected when the form loads, and
so the text field should be disabled. (This is just a further
clarification of rule 2)
3. If the user selects the "magic" radio button, then the text field
should be un-disabled.
So far, I have my form as follows:
[The code below is part of PHP code generating the form output, hence
some embedded variable names. The 'use_*' variables are either empty
or have the value 'checked="checked"', as appropriate.]
::::
<p>
Please choose which source of publications data to use:
</p>
<p>
<label>
<input id="publns_source_repo" name="publns_source"
type="radio" value="repo"
onchange="document.getElementById('publns_uri').disabled =
document.getElementById('publns_source_repo').checked;"
title="Use Publications Repository"
$use_repository />
Use Publications Repository
</label>
<br />
<label>
<input id="publns_source_web" name="publns_source"
type="radio" value="web"
onchange="document.getElementById('publns_uri').disabled =
!document.getElementById('publns_source_web').checked;"
title="Show link to a personal webpage containing
publications data"
$use_webpage />
Show link to a personal webpage containing publications data
</label>
<br />
<label>
<input id="publns_source_local" name="publns_source"
type="radio" value="local"
onchange="document.getElementById('publns_uri').disabled =
document.getElementById('publns_source_local').checked;"
title="Use existing publications database"
$use_localdata />
Use existing publications database
</label>
</p>
<p>
<label for="publns_uri">Web address of personal publications
page</label>
<br />
<span class="hint">
Complete only if you have chosen to display a link to your own
personal webpage of publications data
</span>
<br />
<input id="publns_uri" name="publns_uri"
onload="document.getElementById('publns_uri').disabled =
!document.getElementById('publns_source_web').checked;"
type="text" size="60" value="$publns_webpage_clean" />
</p>
::::
Everything seems to be working, except for when the page is initially
loaded (and when the text field should be enabled or disabled according
to the value of the 'publns_source_web' radio button at that time).
I thought that 'onload' was a valid JavaScript trigger. Does anybody
know where I'm going wrong with my code there?
(There's also the problem that IE and Opera/Win don't seem to ghost
disabled fields, only the *text* within the field, meaning that it's not
obvious that the field is disabled if there is no text in it, in those
cases. I suppose I could add my own custom CSS styles to make the state
of the field clearer..)
Disclaimer: I don't pretend to know any more than the absolute basics of
JavaScript, gleaned from hither and thither on the aethernet over time,
like pollen in the breeze (and so therefore probably out of date and/or
wrong in many ways); if I needed to make significant use of JavaScript,
I would certainly do some proper reading (I have just downloaded the
ECMAScript standard, but I don't really have time to read 258 pages
_just now_, although I am sure it will do me good in the long run), but
I just thought it would be nice to add a *tiny* little sprinkling to my
current project if it was easy to do so. Please turn your flames down
to a moderate heat. ;-)
Thanks for any help,
David.
I'm trying to add a very light sprinkling of JavaScript to a web form as
follows:
0. Of most importance, to me, at least, is that the form must not
_require_ JavaScript in order to function, so this little sprinking is
to be a 'progressive enhancement' only.
1. One input which the user must make on the form is to select 1 of 3
radio buttons to indicate a particular choice.
2. If a particular one of the radio buttons is *not* the selected button
(either at the time the form loads, having read in the user's existing
stored preference data, or as a result of the user selecting 1 of the
other 2 radio buttons), a text input field beneath the radio buttons
should be shown as 'disabled'.
(The "magic" button is the 2nd of 3 in the code below.)
2a. If the user has no existing stored data, then the "magic" radio
button clearly has not already been selected when the form loads, and
so the text field should be disabled. (This is just a further
clarification of rule 2)
3. If the user selects the "magic" radio button, then the text field
should be un-disabled.
So far, I have my form as follows:
[The code below is part of PHP code generating the form output, hence
some embedded variable names. The 'use_*' variables are either empty
or have the value 'checked="checked"', as appropriate.]
::::
<p>
Please choose which source of publications data to use:
</p>
<p>
<label>
<input id="publns_source_repo" name="publns_source"
type="radio" value="repo"
onchange="document.getElementById('publns_uri').disabled =
document.getElementById('publns_source_repo').checked;"
title="Use Publications Repository"
$use_repository />
Use Publications Repository
</label>
<br />
<label>
<input id="publns_source_web" name="publns_source"
type="radio" value="web"
onchange="document.getElementById('publns_uri').disabled =
!document.getElementById('publns_source_web').checked;"
title="Show link to a personal webpage containing
publications data"
$use_webpage />
Show link to a personal webpage containing publications data
</label>
<br />
<label>
<input id="publns_source_local" name="publns_source"
type="radio" value="local"
onchange="document.getElementById('publns_uri').disabled =
document.getElementById('publns_source_local').checked;"
title="Use existing publications database"
$use_localdata />
Use existing publications database
</label>
</p>
<p>
<label for="publns_uri">Web address of personal publications
page</label>
<br />
<span class="hint">
Complete only if you have chosen to display a link to your own
personal webpage of publications data
</span>
<br />
<input id="publns_uri" name="publns_uri"
onload="document.getElementById('publns_uri').disabled =
!document.getElementById('publns_source_web').checked;"
type="text" size="60" value="$publns_webpage_clean" />
</p>
::::
Everything seems to be working, except for when the page is initially
loaded (and when the text field should be enabled or disabled according
to the value of the 'publns_source_web' radio button at that time).
I thought that 'onload' was a valid JavaScript trigger. Does anybody
know where I'm going wrong with my code there?
(There's also the problem that IE and Opera/Win don't seem to ghost
disabled fields, only the *text* within the field, meaning that it's not
obvious that the field is disabled if there is no text in it, in those
cases. I suppose I could add my own custom CSS styles to make the state
of the field clearer..)
Disclaimer: I don't pretend to know any more than the absolute basics of
JavaScript, gleaned from hither and thither on the aethernet over time,
like pollen in the breeze (and so therefore probably out of date and/or
wrong in many ways); if I needed to make significant use of JavaScript,
I would certainly do some proper reading (I have just downloaded the
ECMAScript standard, but I don't really have time to read 258 pages
_just now_, although I am sure it will do me good in the long run), but
I just thought it would be nice to add a *tiny* little sprinkling to my
current project if it was easy to do so. Please turn your flames down
to a moderate heat. ;-)
Thanks for any help,
David.