I'm not a javascripter so this is slightly unfamiliar to me. What I'm
trying to do is that if someone clicks the radio button for Other, then
the text input for other will become enabled.
What is wrong with this? Thank you!
<html>
<head>
<script language="JavaS cript">
<!--
function Package(thisfor m) {
if (thisform.packa ge[3].checked) {
thisform.otherP ackage.disabled = false
} else {
thisform.otherP ackage.disabled = true
}
}
-->
</script>
</head>
<body>
<form name="shipForm" >
<input type="text" name="number" size="5">
<input type="radio" name="package"
onClick=Package (shipForm)>Pall et</span>
<input type="radio" name="package" onClick=Package (shipForm)>Box</span>
<input type="radio" name="package"
onClick=Package (shipForm)>Enve lope</span>
<input type="radio" name="package"
onClick=Package (shipForm)>Othe r</span>
<input type="text" name="otherPack age" disabled>
</form>
</body>
</html> 9 1500
I figured it out. :) No need for a reply.
<ki**********@g mail.com> wrote in message
news:11******** *************@g 44g2000cwa.goog legroups.com... I'm not a javascripter so this is slightly unfamiliar to me. What I'm trying to do is that if someone clicks the radio button for Other, then the text input for other will become enabled.
What is wrong with this? Thank you!
<html> <head> <script language="JavaS cript"> <!-- function Package(thisfor m) {
if (thisform.packa ge[3].checked) { thisform.otherP ackage.disabled = false } else { thisform.otherP ackage.disabled = true }
} --> </script> </head>
<body>
<form name="shipForm" > <input type="text" name="number" size="5"> <input type="radio" name="package" onClick=Package (shipForm)>Pall et</span> <input type="radio" name="package" onClick=Package (shipForm)>Box</span> <input type="radio" name="package" onClick=Package (shipForm)>Enve lope</span> <input type="radio" name="package" onClick=Package (shipForm)>Othe r</span> <input type="text" name="otherPack age" disabled> </form>
</body> </html>
Try this instead.
<html>
<head>
<title>Package. htm</title>
<script type="text/javascript">
function Package(thisfor m) {
if (thisform.packa ge[3].checked) {
thisform.otherP ackage.style.ba ckgroundColor = "#FFFFFF";
thisform.otherP ackage.disabled = false;
thisform.otherP ackage.focus();
} else {
thisform.otherP ackage.value = "";
thisform.otherP ackage.style.ba ckgroundColor = "#DDDDDD";
thisform.otherP ackage.disabled = true;
}
}
</script>
</head>
<body>
<form name="shipForm" >
<input type="text" name="number" size="5">
<input type="radio" name="package"
onClick="Packag e(shipForm)">Pa llet
<input type="radio" name="package"
onClick="Packag e(shipForm)">Bo x
<input type="radio" name="package"
onClick="Packag e(shipForm)">En velope
<input type="radio" name="package"
onClick="Packag e(shipForm)">Ot her
<input type="text" name="otherPack age"
disabled style="backgrou nd-color: #DDDDDD">
</form>
</body>
</html>
Thanks McKirahan. This is something I can learn from. :)
McKirahan wrote: <html> <head> <title>Package. htm</title>
Not Valid. <URL:http://validator.w3.or g/>
<script type="text/javascript"> function Package(thisfor m) {
Identifiers of methods not intended to be used as constructors should not
start with a capital letter, not even to work around a reserved word issue.
function _package(inp)
{
if (thisform.packa ge[3].checked) {
Should be
if (thisform.form. elements['package'][3].checked)
aso. `thisform' is a reference to the HTMLFormElement , but that should
not be passed with `shipForm' (it's IE-proprietary); instead, `this' should
be passed and the `form' property of the referenced event target object
should be used. Form controls should be referenced through the `elements'
collection when possible (as here).
thisform.otherP ackage.style.ba ckgroundColor = "#FFFFFF";
<URL:http://www.w3.org/QA/Tips/color>
thisform.otherP ackage.disabled = false; thisform.otherP ackage.focus();
<URL:http://pointedears.de/scripts/test/whatami#inferen ce>
} else { thisform.otherP ackage.value = ""; thisform.otherP ackage.style.ba ckgroundColor = "#DDDDDD"; thisform.otherP ackage.disabled = true;
Since `thisform.other Package' is used very often, it is prudent to assign
the reference to a variable and use the latter in place once it has been
established that it stores a valid reference:
var o = thisform.otherP ackage;
if (o)
{
o.... = ...
}
or, if the recommendation above is followed:
var f, o;
if (inp
&& (f = inp.form)
&& (o = f.elements)
&& (o = o['otherPackage']))
{
var b = f.elements['package'][3].checked;
if (!b)
{
o.value = "";
}
o.style.backgro undColor = b ? '#fff' : '#ccc';
o.style.color = b ? '#000' : '#333';
o.disabled = b;
if (b && isMethodType(ty peof o.focus))
{
o.focus();
}
}
} } </script> </head> <body> <form name="shipForm" >
Not Valid, the `action' attribute is missing.
<input type="text" name="number" size="5">
type="text" is the default for `input' elements and can be safely omitted.
<input type="radio" name="package" onClick="Packag e(shipForm)">Pa llet <input type="radio" name="package" onClick="Packag e(shipForm)">Bo x <input type="radio" name="package" onClick="Packag e(shipForm)">En velope <input type="radio" name="package" onClick="Packag e(shipForm)">Ot her
But then the `click' event bubbles by default and so could be better handled
at the parent `form' element:
function _package(f)
{
var o;
if (o = f.elements
&& (o = o['otherPackage']))
{
var b = f.elements['package'][3].checked;
if (!b)
{
o.value = "";
}
o.style.backgro undColor = b ? '#fff' : '#ccc';
o.style.color = b ? '#000' : '#333';
o.disabled = b;
if (b && isMethodType(ty peof o.focus))
{
o.focus();
}
}
}
<form ... onclick="_packa ge(this);">
<input type="radio" name="package" id="pkg_pallet " value="pallet"<label for="pkg_pallet ">Pallet</label><br>
<input type="radio" name="package" id="pkg_box" value="box"<label for="pkg_box">B ox</label><br>
<input type="radio" name="package" id="pkg_envelop e" value="envelope "<label for="pkg_envelo pe">Envelope</label><br>
<input type="radio" name="package" id="pkg_other" value="other"<label for="pkg_other" >Other</label><br>
...
</form>
<input type="text" name="otherPack age" disabled style="backgrou nd-color: #DDDDDD">
That color is not Truly Web-Safe[tm], and the foreground color should
be declared, too. See above.
Furthermore, the element should not be disabled by default but in the
`onload' event handler, because otherwise it becomes useless to users
without client-side script support:
<body onload="documen t.forms['shipForm'].elements['otherPackage'].disabled
= true;">
...
<form action="..." name="shipForm" >
...
<input name="otherPack age" style="backgrou nd-color:#ccc; color:#666">
...
</form>
...
</body>
PointedEars
Thomas 'PointedEars' Lahn said the following on 12/30/2005 2:46 AM: McKirahan wrote:
<html> <head> <title>Packag e.htm</title>
Not Valid. <URL:http://validator.w3.or g/>
Irrelevant to the thread. <script type="text/javascript"> function Package(thisfor m) {
Identifiers of methods not intended to be used as constructors should not start with a capital letter, not even to work around a reserved word issue.
Irrelevant to the thread.
function _package(inp) {
if (thisform.packa ge[3].checked) {
Should be
if (thisform.form. elements['package'][3].checked)
If thisform is a reference to the form itself then the reference back to
its form is redundant as you are already at the form level.
aso. `thisform' is a reference to the HTMLFormElement , but that should not be passed with `shipForm' (it's IE-proprietary); instead, `this' should be passed and the `form' property of the referenced event target object should be used. Form controls should be referenced through the `elements' collection when possible (as here).
thisform.otherP ackage.style.ba ckgroundColor = "#FFFFFF";
<URL:http://www.w3.org/QA/Tips/color>
Irrelevant to the thread. thisform.otherP ackage.disabled = false; thisform.otherP ackage.focus();
<URL:http://pointedears.de/scripts/test/whatami#inferen ce>
Irrelevant to the thread. } else { thisform.otherP ackage.value = ""; thisform.otherP ackage.style.ba ckgroundColor = "#DDDDDD"; thisform.otherP ackage.disabled = true;
Since `thisform.other Package' is used very often, it is prudent to assign the reference to a variable and use the latter in place once it has been established that it stores a valid reference:
Irrelevant to the thread.
var o = thisform.otherP ackage; if (o) { o.... = ... }
or, if the recommendation above is followed:
var f, o; if (inp && (f = inp.form) && (o = f.elements) && (o = o['otherPackage'])) { var b = f.elements['package'][3].checked; if (!b) { o.value = ""; }
o.style.backgro undColor = b ? '#fff' : '#ccc'; o.style.color = b ? '#000' : '#333'; o.disabled = b;
if (b && isMethodType(ty peof o.focus)) { o.focus(); } }
} } </script> </head> <body> <form name="shipForm" >
Not Valid, the `action' attribute is missing.
Irrelevant to the thread. <input type="text" name="number" size="5">
type="text" is the default for `input' elements and can be safely omitted.
Irrelevant to the thread. <input type="radio" name="package" onClick="Packag e(shipForm)">Pa llet <input type="radio" name="package" onClick="Packag e(shipForm)">Bo x <input type="radio" name="package" onClick="Packag e(shipForm)">En velope <input type="radio" name="package" onClick="Packag e(shipForm)">Ot her
But then the `click' event bubbles by default and so could be better handled at the parent `form' element:
Irrelevant to the thread.
function _package(f) { var o; if (o = f.elements && (o = o['otherPackage'])) { var b = f.elements['package'][3].checked; if (!b) { o.value = ""; }
o.style.backgro undColor = b ? '#fff' : '#ccc'; o.style.color = b ? '#000' : '#333'; o.disabled = b;
if (b && isMethodType(ty peof o.focus)) { o.focus(); } } }
<form ... onclick="_packa ge(this);"> <input type="radio" name="package" id="pkg_pallet " value="pallet" ><label for="pkg_pallet ">Pallet</label><br> <input type="radio" name="package" id="pkg_box" value="box" ><label for="pkg_box">B ox</label><br> <input type="radio" name="package" id="pkg_envelop e" value="envelope " ><label for="pkg_envelo pe">Envelope</label><br> <input type="radio" name="package" id="pkg_other" value="other" ><label for="pkg_other" >Other</label><br> ... </form>
<input type="text" name="otherPack age" disabled style="backgrou nd-color: #DDDDDD">
That color is not Truly Web-Safe[tm], and the foreground color should be declared, too. See above.
Irrelevant to the thread.
Furthermore, the element should not be disabled by default but in the `onload' event handler, because otherwise it becomes useless to users without client-side script support:
<body onload="documen t.forms['shipForm'].elements['otherPackage'].disabled = true;">
use window.onload, not <body onload
... <form action="..." name="shipForm" > ... <input name="otherPack age" style="backgrou nd-color:#ccc; color:#666"> ... </form> ... </body>
PointedEars
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Answer:It destroys the order of the conversation
On 30/12/2005 12:44, Randy Webb wrote:
[snip] Irrelevant to the thread.
And you've never posted something irrelevant to a thread? What about
others that have? I know you don't like Thomas, but come on, play nice.
--
[...] Answer:It destroys the order of the conversation
Didn't you forget the question?
Mike
--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Thomas 'PointedEars' Lahn <Po*********@we b.de> wrote in
news:46******** ********@Pointe dEars.de: McKirahan wrote:
<html> <head> <title>Package. htm</title> Not Valid. <URL:http://validator.w3.or g/>
Really?
The content for the TITLE element is parsed character data (#PCDATA), and
apparently can even include character references (character entity and
numeric character references). The HTML 4.01 specification refers the
reader to the ISO 8879 standard for a definitive reading of #PCDATA.
Cutting and pasting this HTML into the W3C validator and setting Doctype
for 4.01 Transitional, there was only one error making it invalid, which
was the missing 'action' attribute for the form element.
You must have caught the validator when it had a fever that day. ;-)
[excised rest of message] PointedEars
Patient Guy wrote: Thomas 'PointedEars' Lahn <Po*********@we b.de> wrote [...]: McKirahan wrote: <html> <head> <title>Package. htm</title> Not Valid. <URL:http://validator.w3.or g/>
Really?
Really.
The content for the TITLE element is parsed character data (#PCDATA), and apparently can even include character references (character entity and numeric character references). [...]
I was not referring to the `title' element, but to all of the quoted code up
to this line which lacks the DOCTYPE declaration and lacks the character
set declaration for non-HTTP service. The snippet claims to be a HTML
document; it is not.
Cutting and pasting this HTML into the W3C validator and setting Doctype
^^^^^^^^^^^^^^^ for 4.01 Transitional,
^^^^^^^^^^^^^^^ ^^^^^^
See?
there was only one error making it invalid, which was the missing 'action' attribute for the form element.
You have not validated the document through file upload which would have
revealed the missing character set declaration, too.
PointedEars
Michael Winter said the following on 12/30/2005 10:34 AM: On 30/12/2005 12:44, Randy Webb wrote:
[snip]
Irrelevant to the thread.
And you've never posted something irrelevant to a thread? What about others that have? I know you don't like Thomas, but come on, play nice.
Yes sir :) --
[...]
Answer:It destroys the order of the conversation
Didn't you forget the question?
Or forgot to snip it all :)
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sarah Tanembaum |
last post by:
Beside its an opensource and supported by community, what's the fundamental
differences between PostgreSQL and those high-price commercial database (and
some are bloated such as Oracle) from software giant such as Microsoft SQL
Server, Oracle, and Sybase?
Is PostgreSQL reliable enough to be used for high-end commercial
application? Thanks
|
by: typingcat |
last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so
on. I've tried many PHP IDEs today, but almost non of them supported
Unicode (UTF-8) file.
I've found that the only Unicode support IDEs are DreamWeaver 8 and
Zend PHP Studio.
DreamWeaver provides full support for Unicode. However, DreamWeaver is
a web editor rather than a PHP IDE. It only supports basic IntelliSense
(or code completion) and doesn't have anything...
|
by: Alfonso Morra |
last post by:
Hi,
I am at the end of my tether now - after spending several days trying to
figure how to do this. I have finally written a simple "proof of
concept" program to test serializing a structure containing pointers
into a "flattened" bit stream.
Here is my code (it dosen't work).
I would be grateful for any feedback that helps fix this. My intention
|
by: Keith K |
last post by:
Having developed with VB since 1992, I am now VERY
interested in C#. I've written several applications with
C# and I do enjoy the language.
What C# Needs:
There are a few things that I do believe MSFT should do to
improve C#, however.
I know that in the "Whidbey" release of VS.NET currently
|
by: Jason Huang |
last post by:
Hi,
Would someone explain the following coding more detail for me? What's the
( ) for?
CurrentText = (TextBox)e.Item.Cells.Controls;
Thanks.
Jason
| |
by: Aaron Ackerman |
last post by:
I cannot a row to this bound DataGrid to SAVE MY LIFE! I have tried
everything and I am at a loss. The using goes into add mode with the add
button adds his data then updates with the update button, seems simple.
I am using ALL visual controls (supposedly to simplify things. If I was not
using the visual controls and calling an ExecuteNonQuery no prob.
Please look at my code and tell me what I am doing wrong. Also, what are the
advatages...
|
by: Ajay |
last post by:
Hi all,
i want to know when i create a class.what all it contains.I
know the following things are there by default if i do not declare them
by myself.Please tell the other things that are left.
1. constructor
2.Destructor
3.Copy constructor
4. Assignment operator
|
by: watkinsdev |
last post by:
Hi,
I have created a mesh class in visual studio 6.0 c++.
I can create a device, render objects and can edit the objects by for
instancnce selecting a cluster of vertices and processing the vertices
and can do this multiple times on a sinlge vertex cluster.
The problem I have been encoutering is that, if I select a second
vertex cluster and try to edit that , the program crashes.
|
by: shapper |
last post by:
Hello,
I am creating a class with a control. I compiled the class and used it
on an Asp.Net 2.0 web site page.
I can see the begin and end tags of my control (<oland </ol>) but
somehow the child controls (just a literal for testing) of my control
is not being added to the page.
Could someone tell me what am I doing wrong?
|
by: DavidSeck.com |
last post by:
Hi,
I am working with the Facebook API right now, an I have kind of a
problem, but I don't know what I am doing wrong.
So I have a few arrays, f.ex.:
User albums:
array(2) {
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |