473,231 Members | 1,888 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,231 software developers and data experts.

enabling form elements

hi all,

I try to enable some form elements (positie and fotoToevoegen) when a user
clicks a checkbox. Sadly enough it doesn't work I use the
'onSelect="EnableInput();'. The function is defined inside the form. Maybee
someone knows the problem?

kind regards
Stijn

<form name="nieuws" method="post"
action="nieuwsVoegToe.php?actie=nieuw&IDN=">
Titel <input class="grijs" name="titel" type="text" size="40">
<select class="grijs" name="type" >
</select>
<textarea class="grijs1" name="inhoud" cols="80"
rows="8"></textarea><br><br>

<script LANGUAGE="JavaScript">
function EnableInput()
{
document.nieuws.positie.Disabled = "False";
document.nieuws.fotoToevoegen.Disabled = "False";
}
</script>

foto toevoegen? <input name="fotoToevoegen" type="checkbox" value="1"
onSelect="EnableInput();"><br>
<table class="grijs" bgcolor="#EEEEEE" >
<tr><td>
selecteer je foto:
<input type="hidden" name="MAX_FILE_SIZE" value="20000">
<input type="file" name="foto">
</td></tr>
<tr>
<td>
<table>
<tr>
<td><img src="images/imageBoven.jpg"></td>
<td><img src="images/imageRechts.jpg"></td>
<td><img src="images/imageOnder.jpg"></td>
<td><img src="images/imageLinks.jpg"></td>
</tr>
<tr align="center">
<td><input type="radio" name="positie" value="boven"></td>
<td><input type="radio" name="positie" value="rechts"></td>
<td><input type="radio" name="positie" value="onder"></td>
<td><input type="radio" name="positie" value="links"></td>
</tr>
</table>
</td>
</tr>
</table><br>
<input class="grijs" type="submit" value="nieuws toevoegen >>">
</form>
Jul 23 '05 #1
7 1495


Stijn Goris wrote:

document.nieuws.positie.Disabled = "False";


The property is named disabled and the boolean value is false and not
"False" so you need
document.nieuws.positie.disabled = false;

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
Stijn Goris wrote:
<script LANGUAGE="JavaScript">
<script type="text/javascript">

The language attribute is deprecated.
function EnableInput()
function EnableInput(theForm)

Note the form reference now being passed to the function. This is to prevent
needing to hard-code "document.nieuws" later.

I like to use Java syntax conventions in JavaScript, and I tend to use the
shortest variable that will give me some indication of what the paramter is,
which would make it "function enableInput(f)", but use whatever you're
comfortable with.
{
document.nieuws.positie.Disabled = "False";
document.nieuws.fotoToevoegen.Disabled = "False";
theForm.positie.disabled = false;
theForm.fotoToevoegen.disabled = false;

false is a boolean, not a String, by setting the property to the String
"false", you are in fact making it true (because a non-empty string evaluates
to true). Also, JavaScript is case-sensitive, so the property "disabled" must
be lowercase.
}
</script>

foto toevoegen? <input name="fotoToevoegen" type="checkbox" value="1"
onSelect="EnableInput();"><br>


onselect="EnableInput(this.form);"

Pass a reference to the form to the function. This gets picked up as "theForm"
in the function and removes the need to hard-code the name of the form in the
function (which means it doesn't break if you decide to rename the form).

I like to make my attributes all lowercase in HTML, including JavaScript
events. Since the attribute is part of the HTML markup and not JavaScript, it
isn't case-sensitive.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #3

"Grant Wagner" <gw*****@agricoreunited.com> wrote in message
news:41***************@agricoreunited.com...
Stijn Goris wrote:
<script LANGUAGE="JavaScript">
<script type="text/javascript">

The language attribute is deprecated.
function EnableInput()


function EnableInput(theForm)

Note the form reference now being passed to the function. This is to

prevent needing to hard-code "document.nieuws" later.

I like to use Java syntax conventions in JavaScript, and I tend to use the
shortest variable that will give me some indication of what the paramter is, which would make it "function enableInput(f)", but use whatever you're
comfortable with.
{
document.nieuws.positie.Disabled = "False";
document.nieuws.fotoToevoegen.Disabled = "False";
theForm.positie.disabled = false;
theForm.fotoToevoegen.disabled = false;

false is a boolean, not a String, by setting the property to the String
"false", you are in fact making it true (because a non-empty string

evaluates to true). Also, JavaScript is case-sensitive, so the property "disabled" must be lowercase.
}
</script>

foto toevoegen? <input name="fotoToevoegen" type="checkbox" value="1"
onSelect="EnableInput();"><br>
onselect="EnableInput(this.form);"

Pass a reference to the form to the function. This gets picked up as

"theForm" in the function and removes the need to hard-code the name of the form in the function (which means it doesn't break if you decide to rename the form).

I like to make my attributes all lowercase in HTML, including JavaScript
events. Since the attribute is part of the HTML markup and not JavaScript, it isn't case-sensitive.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq


thanks for the nice reply but I still have trouble making it work.

I have the javascript function on top of the file

<script type="text/javascript">
function EnableInput(theForm)
{
theForm.positie.disabled = false;
theForm.foto.disabled = false;
}
</script>

then the form
<form name="nieuws" enctype="multipart/form-data" method="post"
action="nieuwsVoegToe.php?actie=nieuw&IDN=">
Titel <input class="grijs" name="titel" type="text" size="40">
<select class="grijs" name="type" >test</select>
<textarea class="grijs1" name="inhoud" cols="80"
rows="8"></textarea><br><br>
foto toevoegen? <input name="fotoToevoegen" type="checkbox" value="1"
ondelect="EnableInput(this.form);"><br>
<table class="grijs" bgcolor="#EFEFEF" >
<tr><td>
selecteer je foto:
<input type="hidden" name="MAX_FILE_SIZE" value="20000">
<input disabled type="file" name="foto">
</td></tr>
<tr>
<td>
<table>
<tr>
<td><img src="images/imageBoven.jpg"></td>
<td><img src="images/imageRechts.jpg"></td>
<td><img src="images/imageOnder.jpg"></td>
<td><img src="images/imageLinks.jpg"></td>
</tr>
<tr align="center">
<td><input disabled type="radio" name="positie" value="boven"></td>
<td><input disabled type="radio" name="positie" value="rechts"></td>
<td><input disabled type="radio" name="positie" value="onder"></td>
<td><input disabled type="radio" name="positie" value="links"></td>
</tr>
</table>
</td>
</tr>
</table><br>
<input class="grijs" type="submit" value="nieuws toevoegen >>">
</form>

Thank in advance
Stijn
Jul 23 '05 #4
On Tue, 27 Jul 2004 17:23:34 GMT, Grant Wagner
<gw*****@agricoreunited.com> wrote:
[snipped]
I like to make my attributes all lowercase in HTML, including JavaScript
events. Since the attribute is part of the HTML markup and not JavaScript, it
isn't case-sensitive.


Hi,

I'm currently reading javascript: the Definitive Guide, (Excellent
book BTW) and find it very usefull.... That is also pointing out to
use all the attributes in lowercase as its HTML. eg

onclick, onmouseover, onmouseout

But I'm having a problem with doing it this way.... it works fine in
IE 6 But I also test my pages in NS 7.1 and that doesn't work when I
put them in lowercase, it just seems to ignore the attibutes. I seem
to have to put them as javascript:

onClick, onMouseOver, onMouseOut.

is it me or does everyone else get this problem ? is it a setting in
NS ?

Thanks

Al.

Jul 23 '05 #5
Stijn Goris wrote:
foto toevoegen? <input name="fotoToevoegen" type="checkbox" value="1"
ondelect="EnableInput(this.form);"><br>


checkbox inputs don't have an ondelect event, nor do they have an onselect event
(well, they might, but it's not appropriate for this purpose). What you want is:

<input name="fotoToevoegen" type="checkbox" value="1"
onclick="EnableInput(this);">

and your function should be:

function EnableInput(chkbox) {
var f = chkbox.form;
f.foto.disabled = !chkbox.checked
var radioButtons = f.positie;
if (typeof radioButtons.length == 'undefined') {
// normalize a single radio button to an array
radioButtons = [ radioButtons ];
}
// handle one or more radio buttons as an array
for (var i = 0; i < radioButtons.length; i++) {
radioButtons[i].disabled = !chkbox.checked;
}
}

Note that you can't simply set the radio button collection disabled=false, you
must determine if there is more then one radio button and then loop through
them, changing each disabled property individually.

Also note that I am using the state of the chkbox (chkbox.checked) to determine
what to set the disabled property to, this means if they uncheck the box later
the various inputs will become disabled again (you may want to reset the checked
property on each of the radio buttons too, to clear any selection they've made,
that's optional).

Of course, now you've created a situation where the inputs are disabled by
default and enabled using JavaScript. If JavaScript is disabled or unavailable,
those inputs will _never_ be available. Better to leave all the inputs enabled
by default, then in <body onload="..."> set them disabled programmatically.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #6
Harag wrote:
I'm currently reading javascript: the Definitive Guide, (Excellent
book BTW) and find it very usefull.... That is also pointing out to
use all the attributes in lowercase as its HTML. eg
onClick, onMouseOver, onMouseOut.

is it me or does everyone else get this problem ? is it a setting in
NS ?


It's you, NS works the same way as IE in this case.
Mick
Jul 23 '05 #7
On Wed, 28 Jul 2004 17:52:06 GMT, Mick White
<mw******@BOGUSrochester.rr.com> wrote:
Harag wrote:
I'm currently reading javascript: the Definitive Guide, (Excellent
book BTW) and find it very usefull.... That is also pointing out to
use all the attributes in lowercase as its HTML. eg


onClick, onMouseOver, onMouseOut.

is it me or does everyone else get this problem ? is it a setting in
NS ?


It's you, NS works the same way as IE in this case.
Mick

Yep, it was, thanks. I changed my code again and it seems to work this
time. maybe it was a typo last time I tried it.

Thanks

AL
Jul 23 '05 #8

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

Similar topics

1
by: TheKeith | last post by:
I'm currently working on a form for my site and would like to do something that I've seen many times on other sites. I would like to make a particular form element enabled or disabled depending on...
4
by: Frank Way | last post by:
Hi all, I've googled this one to death, and still can't find an answer. Not sure I'm asking the right question, but here goes: Have a form with an onSubmit that has some javscript to disable...
3
by: Bryan Capps | last post by:
I have a text box control on a form, the value of which is calculated (concatenated) from entries on a subform. Accordingly, I've set the control's locked property to true and the tab stop...
2
by: HumptyDumpty | last post by:
Does anyone know if there is a problem with re-enabling the Screen Saver after it has been disabled programmatically. I am using the SystemParametersInfo function within User32.dll, and have...
10
by: Robert Jacobson | last post by:
Hi, I'm develing a COM add-in for Microsoft Word XP that displays a form. I'd like to have the form display using the Windows XP theme. However, neither using a manifest nor calling...
2
by: dougawells | last post by:
Hi- I'm wanting to have a set of radio buttons disabled when a form is displayed, then if they check another specific radio button, those would become enabled. I've tried setting it via...
1
by: Evan Nelson | last post by:
We are running our website on 3 W2K servers using classic ASP and IIS 5.0. Because the servers are load balanced we don't use the ASP Session object instead we store session type information to the...
1
by: hello2008 | last post by:
Hi, I have just started coding in PHP. I have coded a web page using HTML, JS, and PHP. An HTML table has to be populated dynamically using the data from the backend. Presently I have 5...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.