Here is my code:
<SCRIPT>
function transportchange(transport) {
if (framenewinstall.Helpdesk.checked)
framenewinstall.Helpdesk.checked=false;
if (framenewinstall.CircuitNumber.checked)
framenewinstall.CircuitNumber.checked=false;
switch (transport) {
case 0:
Helpdesk.innerText="No Info Needed";
CircuitNumber.innerText="FMS Number";
break;
case 1:
Helpdesk.innerText="GTS Contact Number";
CircuitNumber.innerText="Circuit Number";
break;
}
}
</SCRIPT>
<FORM method="POST" name="framenewinstall"
action="http://server/cgi-bin/Erik-FormMail.pl">
<INPUT TYPE="RADIO" NAME="Transport" VALUE="Sprint"
onclick="transportchange(0);" CHECKED>
Sprint
<INPUT TYPE="RADIO" NAME="Transport" VALUE="GTS"
onclick="transportchange(1);">
GTS<BR>
<input type="text" name="Helpdesk">
<label id="Helpdesk" for="Helpdesk">Helpdesk</label><BR>
<INPUT TYPE="text" NAME="CircuitNumber">
<LABEL ID="CircuitNumber" FOR="CircuitNumber">Circuit
Number</LABEL> <BR>
It is working, meaning that it changes the html OUTSIDE of the field
itself. But what I am looking to do is auto populate the helpdesk phone
# inside the field, depending on whether you select Sprint or GTS. I
thought it would be called an initval but that is not it. 3 2261 ew*******@hotmail.com wrote: Here is my code: <SCRIPT> function transportchange(transport) { if (framenewinstall.Helpdesk.checked)
Problems start here, IE Win only reference :
"framenewinstall.Helpdesk.checked"
framenewinstall.Helpdesk.checked=false; if (framenewinstall.CircuitNumber.checked) framenewinstall.CircuitNumber.checked=false; switch (transport) { case 0: Helpdesk.innerText="No Info Needed"; CircuitNumber.innerText="FMS Number";
innerText is IE Win only reference
break; case 1: Helpdesk.innerText="GTS Contact Number"; CircuitNumber.innerText="Circuit Number"; break;
No default?
Should I continue?
[snip]
Mick
I found my issue. I used the name helpdesk in too many places. I made
it helpdesk1 and that fixed it.
Thanks. ew*******@hotmail.com wrote: I found my issue. I used the name helpdesk in too many places. I made it helpdesk1 and that fixed it.
Thanks.
I believe you have many more issues than you think. Your code
is exclusive to IE - making it cross browser is quite simple
(see below).
You have created duplicate id/name attributes incorrectly,
and your interface is illogical.
From your first post:
<SCRIPT>
<script type="text/javascript">
The type attribute is required.
function transportchange(transport) { if (framenewinstall.Helpdesk.checked) framenewinstall.Helpdesk.checked=false;
This syntax is IE only, a cross-browser version is:
if (document.framenewinstall.Helpdesk.checked)
document.framenewinstall.Helpdesk.checked=false;
if (framenewinstall.CircuitNumber.checked) framenewinstall.CircuitNumber.checked=false;
Same here:
if (document.framenewinstall.CircuitNumber.checked)
document.framenewinstall.CircuitNumber.checked=fal se;
A bigger issue is that this appears to be code for checkboxes,
not radio buttons. It also does nothing in either Firefox or IE
that I can tell - the radio button stays checked.
Do you want to use checkboxes and use the above function to make
them mutually exclusive? In that case, clicking on
"CicuitNumber" should un-check Helpdesk and vice versa.
switch (transport) { case 0: Helpdesk.innerText="No Info Needed"; CircuitNumber.innerText="FMS Number"; break;
More IE-only nastiness that is simply not necessary. I've
substituted a variable to shorten the line length.
var f = document.framenewinstall;
switch (transport) {
case 0:
f.Helpdesk.value = "No Info Needed";
f.CircuitNumber.value = "FMS Number";
break;
Use 'value' not 'innerText'. It is DOM compliant and works in
many more browsers than 'innerText'.
case 1: Helpdesk.innerText="GTS Contact Number"; CircuitNumber.innerText="Circuit Number"; break;
case 1:
f.Helpdesk.innerText="GTS Contact Number";
f.CircuitNumber.innerText="Circuit Number";
break;
default:
return false; // or do something useful
As Mick said, you should have a default too.
} } </SCRIPT> <FORM method="POST" name="framenewinstall" action="http://server/cgi-bin/Erik-FormMail.pl"> <INPUT TYPE="RADIO" NAME="Transport" VALUE="Sprint" onclick="transportchange(0);" CHECKED> Sprint <INPUT TYPE="RADIO" NAME="Transport" VALUE="GTS" onclick="transportchange(1);"> GTS<BR> <input type="text" name="Helpdesk"> <label id="Helpdesk" for="Helpdesk">Helpdesk</label><BR>
<INPUT TYPE="text" NAME="CircuitNumber"> <LABEL ID="CircuitNumber" FOR="CircuitNumber">Circuit Number</LABEL> <BR>
Here you found one issue with your use of the name "Helpdesk",
but you also have the same issue with your labels having an ID
the same as the name of a different element. Labels don't need
an ID, so don't give them one.
And the label's "for" attribute should match an ID, not a name.
<URL:http://www.w3.org/TR/html4/interact/forms.html#edef-LABEL>
"for = idref [CS]
This attribute explicitly associates the label being defined
with another control. When present, the value of this
attribute must be the same as the value of the id attribute
of some other control in the same document. When absent, the
label being defined is associated with the element's
contents."
You have done the right thing and made one radio button checked,
but don't put the associated values into the text input.
The labels on the text inputs are a bit useless, better to put
them on the radio buttons so clicking on the label selects the
button.
Here is a version that works, I've set default values on the
text inputs and made them readonly, you may want to have an
onload function that sets the values according to the radio
button that is selected by default.
If you actually want checkboxes, then post again.
<SCRIPT type="text/javascript">
function transportchange(transport) {
var f = document.framenewinstall;
switch (transport) {
case 0:
f.Helpdesk.value="No Info Needed";
f.CircuitNumber.value="FMS Number";
break;
case 1:
f.Helpdesk.value="GTS Contact Number";
f.CircuitNumber.value="Circuit Number";
break;
default:
return false;
}
}
</SCRIPT>
<FORM method="POST" name="framenewinstall"
action="http://server/cgi-bin/Erik-FormMail.pl">
<label for="Transport0">
<INPUT TYPE="RADIO" NAME="Transport" id="Transport0"
VALUE="Sprint" onclick="transportchange(0);"
CHECKED> Sprint</label>
<label for="Transport1">
<INPUT TYPE="RADIO" NAME="Transport" id="Transport1"
VALUE="GTS" onclick="transportchange(1);" GTS</label><BR>
<label for="Helpdesk">
<input type="text" readonly name="Helpdesk"
id="Helpdesk" value="No Info Needed" Helpdesk</label>
<BR>
<label for="CircuitNumber">
<INPUT TYPE="text" readonly NAME="CircuitNumber"
id="CiruitNumber" value="FMS Number" Circuit Number</label>
<BR>
<input type="reset">
</form>
--
Rob This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: JDS |
last post by:
Hi, all. I'd like to do the following, preferably *without* resorting to
JavaScript:
I have a long, dynamically-generated form questionnaire. Not all of the
form fields are dynamically...
|
by: Andres Eduardo Hernando |
last post by:
Hi,
I'm not entirely sure this is the right group to ask this question, but I saw a similar one above, and the group's
charter is not clear enough about it, so, here I go: ;)
What is the...
|
by: mitch-co2 |
last post by:
What I am trying to do is when someone clicks on the YES radio button I
want the text field called MYTEXT to equal the text field named DATE.
The below code works as long as I do NOT UN-COMMENT...
|
by: Alpha |
last post by:
I have 3 radio buttons for include, exclued or 'select all' from the listbox
items. If a user selects the 'Select All' button' then all items in listbox
is hi-lited as selected. Now, when user...
|
by: Sourav Dutta Gupta |
last post by:
I am having some problem regarding radiobutton inside a datalist. I want to
have a radiobutton on each row of my datalist. I want to check a particular
button, all the other would remain unchecked....
|
by: namanhvu |
last post by:
Hi everyone,
I'm trying to create a form where the radio button is automatically
selected when the input text field beside it is clicked. I know I need
to use "onClick" somewhere but I don't...
|
by: wreed |
last post by:
I have a for loop seen below....
var the_form = document.getElementById(formName);
for(var i=0; i<the_form.length; i++)
{
var temp = the_form.elements.type;
if (temp == "radio")
{
for (x =...
|
by: Carlos |
last post by:
Hi all,
I have a form with an input radio control in a template field.
When the user selects an option, and press a button
the selection disappears.. I would like the selection to
persist after...
|
by: FunkHouse9 |
last post by:
I'm trying to develop an order page and in one section, the customer specifies a shipment type using radio buttons that is submitted to the shopping cart. There are 4 buttons. If either of the...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |