473,406 Members | 2,620 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,406 software developers and data experts.

Enabling disabled option

KeredDrahcir
426 256MB
Can somebody help me. I'm trying to set a disabled option to enabled when the user click on a link. I've tried just about everything and I'm practically pulling my hair out.

The option I want to enable is a test box.
Expand|Select|Wrap|Line Numbers
  1. <input type="text" name="input_name<?=$i;?>" id="input_id<?=$i;?>" value="<?=$class->value;?>" disabled="true" size="4"/>
The code to enable it calls a function.
Expand|Select|Wrap|Line Numbers
  1. <img alt="" src="images/img.gif" onclick="disable_enable(<?=$i;?>);"/>
The function is:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="JavaScript">
  2.   function disable_enable($i)
  3.   {
  4.     elements="input_name"+$i;
  5.     document.form.elements.disabled=false;
  6.   }
  7. </script>
I've also tried using a getElementById in the onclick and tried using document.form... in the onclick and just can't seem to get the textbox to enable. Am I missing something really simple?
Sep 23 '10 #1
17 1734
Dormilich
8,658 Expert Mod 8TB
first, disabled is a HTML standalone attribute. if you want to set a value, then use "disabled".

document.form.elements is an element collection (but maybe even the document.form call is already invalid*) and as such doesn’t have a .disabled property.

* - it is good coding practice to not use HTML/CSS/JavaScript keywords as variable names
Sep 23 '10 #2
KeredDrahcir
426 256MB
I'm not calling the form form. I'm just using that in place of my form name.

I'm not sure what you mean by an element collection.
Sep 23 '10 #3
Dormilich
8,658 Expert Mod 8TB
the same thing that is returned when (for instance) calling document.getElementsByName(). document.form_name.elements does the same for all form controls in a form.
Sep 23 '10 #4
KeredDrahcir
426 256MB
All the websites I've been to tell me that the code is used is correct.
What is the correct way to re-enable the element?
Sep 23 '10 #5
Dormilich
8,658 Expert Mod 8TB
set the .disabled property of the form control to false.
Sep 23 '10 #6
KeredDrahcir
426 256MB
I need it be disabled to begin with.
Sep 23 '10 #7
Dormilich
8,658 Expert Mod 8TB
set the disabled attribute and do nothing in JavaScript.
Sep 23 '10 #8
KeredDrahcir
426 256MB
I thought I needed JavaScript to enable it. How do I enable it without JavaScript?
Sep 23 '10 #9
Dormilich
8,658 Expert Mod 8TB
a form control in its default configuration is always enabled. to disable it you either set the disabled attribute in HTML or set in JavaScript the .disabled property to true.
Sep 23 '10 #10
KeredDrahcir
426 256MB
I've set the it as disabled. I want to enable it if the user clicks on the image. That why I want to use JavaScript. I don't want that filed to be posted unless the image has been clicked on.
Sep 23 '10 #11
Dormilich
8,658 Expert Mod 8TB
then use the click event to set the .disabled property to false.
Sep 23 '10 #12
KeredDrahcir
426 256MB
I've tried that and it's not working. That's why I came here.
Sep 23 '10 #13
KeredDrahcir
426 256MB
Is there anything else I can try?
Sep 23 '10 #14
Dormilich
8,658 Expert Mod 8TB
you can try it with a form control object.
Sep 23 '10 #15
KeredDrahcir
426 256MB
I've finally fixed it but you've been 100% unhelpful.
Sep 30 '10 #16
Dormilich
8,658 Expert Mod 8TB
it’s not my fault alone, if we don’t understand, what we’re talking about.
Sep 30 '10 #17
KeredDrahcir
426 256MB
I tried to be as clear as possilbe in my original post. It just looked as if you hadn't read that.
Sep 30 '10 #18

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

Similar topics

2
by: Targa | last post by:
I have a select box with about 5 options. I need to have one of the options, when selected, display a second select box. The second select box is populated by a database and needs to be preloaded...
4
by: Old Lady | last post by:
Hi, I need help! I have a SELECT/OPTION list. My goal is to have a TEXT input field in a form that is normally disabled, but it should become enabled when the user select one predefined OPTION....
1
by: Stewart Cambridge London, UK | last post by:
I've been having some trouble with a set of <select><optgroup><option> dropdowns. I've been experimenting with the disabled attribute in the <optgroup> and <option> tags. Seems to work in NN...
5
by: Georges Heinesch | last post by:
Hi. I created an option group using the wizard. I included 3 option buttons. An option group (in general) can be enabled or disabled completely (includung option buttons and their respective...
6
by: indhu | last post by:
hi all after a long time am back.. happy new year guys form name: task_allot table: task field taskid is a combo gets the value from scene table option group name taskcategory= mod,tex,lig. ...
8
by: Richard Maher | last post by:
Hi, I am in a mouseup event for button A and I'd like to disable=false button B before starting some work. Is there anyway that an event for button B can then fire before my event processing for...
2
by: Meendar | last post by:
Hi, Is there any possible way to get parameter values from the disabled <selectof html. Thanks in Advance!
1
by: Malinmore | last post by:
the following works well regarding one select box with one hidden text box. however I need two unique select boxes with relevant hidden text boxes that un-hide when the Add New option is selected....
17
by: govolsbaby | last post by:
Is there a way to leave the button forecolor unchanged when it is disabled? I have multiple buttons on the form and depending on various user inputs, some will or will not be enabled but I'd...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.