473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

initval inside my field when radio button is selected

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.

Jul 23 '05 #1
3 2316
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
Jul 23 '05 #2
I found my issue. I used the name helpdesk in too many places. I made
it helpdesk1 and that fixed it.

Thanks.

Jul 23 '05 #3
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>&nbsp;Sprint</label>

<label for="Transport1">
<INPUT TYPE="RADIO" NAME="Transport" id="Transport1"
VALUE="GTS" onclick="transportchange(1);"&nbsp;GTS</label><BR>
<label for="Helpdesk">
<input type="text" readonly name="Helpdesk"
id="Helpdesk" value="No Info Needed"&nbsp;Helpdesk</label> <BR>
<label for="CircuitNumber">
<INPUT TYPE="text" readonly NAME="CircuitNumber"
id="CiruitNumber" value="FMS Number"&nbsp;Circuit&nbsp;Number</label>

<BR>

<input type="reset">
</form>
--
Rob
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
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...
10
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...
4
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...
3
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...
3
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....
1
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...
9
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 =...
10
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...
1
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.