473,471 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Why won't my function work?

40 New Member
Hi all,

I've got a simple function I can't get to work. I've got two checkboxes that are associated with two textarea inputs. I disable the text areas initially. When the associated checkbox is clicked, I want it to enable that text area... and vice versa. Like a toggle.

My form is called pay_form. (The form actually spans several tables, in case that matters). Here's the tag for it:

Expand|Select|Wrap|Line Numbers
  1. <form ACTION="checkout3.php" method="POST" name="pay_form" id="pay_form" onSubmit="return chkPayForm();" style="margin:0;">
Here are the two checkboxes:

Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" name="commentbox" id="commentbox" value="0" onClick="msgBox('order_msg');" align="bottom"/>
  2.  
  3. <input type="checkbox" name="giftbox" id="giftbox" value="0" onClick="msgBox('gift_msg');" align="bottom"/>
And here are the two associated textareas:

Expand|Select|Wrap|Line Numbers
  1. <textarea name="order_msg" id="order_msg" cols="20" rows="3" maxlength="255" disabled></textarea>
  2.  
  3. <textarea name="gift_msg" id="gift_msg" cols="40" rows="3" maxlength="255" disabled></textarea>
Finally, here is my function:

Expand|Select|Wrap|Line Numbers
  1. function msgBox(element) {
  2.  var frm = document.pay_form;
  3.  if (frm.element.disabled == true) {
  4.     frm.element.disabled = false;
  5.     } else { frm.element.disabled = true; }
  6. }
Am I doing the parameter passing correctly? How come the textareas aren't toggling on and off? Please help! :) Thanks in advance.
Dec 14 '07 #1
3 1437
acoder
16,027 Recognized Expert Moderator MVP
Try this instead:
Expand|Select|Wrap|Line Numbers
  1. function msgBox(element) {
  2.  var txtarea = document.getElementById(element);
  3.  if (txtarea.disabled == true) {
  4.     txtarea.disabled = false;
  5.     } else { txtarea.disabled = true; }
  6. }
Use the ID whenever you can to access elements.
Dec 14 '07 #2
vozzek
40 New Member
Hey that worked! Thanks!

Being a javascript newbie, I've never used getElementById. Gonna have to go check out more about it. Thanks again.
Dec 14 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
Glad it helped. Have a look at this link.
Dec 17 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: lawrence | last post by:
I've this function, which is the method of a class. I'm posting the constructor of the class down below. For some reason, when I fill out a form and hit submit, I'm not getting any values. Can...
4
by: Mark Hayworth | last post by:
Randy: I too am having the problem that this other guy/girl had. I put in the proper API declarations and arguments for GetPrivateProfileString yet it doesn't return the correct stuff. It always...
3
by: Dave C | last post by:
I've written the following code that won't compile, trimmed down to just the pertinent stuff: --- WindowClass.hxx ---------------------------------------------------- #include <set> class...
4
by: Wm | last post by:
I have a script that changes a main/enlarged image when you click on a thumbnail. It works fine in IE, but for some reason it won't do anything in Netscape 7.1. Does anyone know if this is a...
6
by: Joop | last post by:
Hi all, I'm kinda new to JavaScript, but hey... I'm trying anyway! ;-) So, here's my problem : I've created a table in my document, presenting a list of items, one can 'select' by clicking...
8
by: nescio | last post by:
hello, i have got a javascript that opens a new window. when i call the javascript function i want to ad a variable. what you see on the pop up depends on the variable. but the variable in...
1
by: cookieplanter | last post by:
I need to add content to two DIVs on page load but this just won't work. If I call any one function, things work fine or if I trigger the events on-click, it works perfectly. But with both together...
2
by: Altman | last post by:
I have created an ascx control and I am calling registerclientscriptblock. The path to the js file is relative to the aspx page and not the ascx file. The function runs fine in IE7 but in...
4
by: mikeyfrombrighton | last post by:
Hi all, Strange thing. I want users to be able to go back to a list of products after they have looked at their shopping basket. Whilst in their shopping basket they may make edits etc so it's...
2
by: Matthew Wells | last post by:
Hello. I'm reposting this because my prioe post's subject line was incorrect. I'm developing an asp.net 2.0 project using VS 2005 on XP sp2 with all the updates. I have an aspx page with...
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...
1
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...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.