473,406 Members | 2,371 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.

Sending disabled form elements

Hello all,

I am stuck with my problem, and being a JS novice, I need your help. I'd appreciate it if anyone could.

I have a page, in which depending on value selected from dropdown-1 (for example), I need to disable or enable few other elements in the page.

I then need to send all these values via form submit to another page. Problem is, I discovered that disabled elements cannot be sent via form submits.

My solution is that I use the readOnly property, instead of disabled. But the following code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. if (value == "Ordered" || value == "Planned")
  3. {
  4.          document.myForm.myElement.readOnly = false;
  5. }
  6. else if (value != "Disposed")
  7. {
  8.          document.equipment.myElement.readOnly = true;
  9. }
  10.  
  11.  
The field myElement in my case is a drop down.

Thanks for the help.

Regards,
Trupti
May 7 '10 #1
6 2284
acoder
16,027 Expert Mod 8TB
Is the form name myForm or equipment?
May 7 '10 #2
@acoder
Hello,

I'm sorry; its actually 'equipment', but because I didn't want to confuse anyone, I decided to substitute it with 'myForm'. Evidently, I skipped it in one place.

Let us take the name to be 'myForm'. I'm re-writing my above code snippet here:

Expand|Select|Wrap|Line Numbers
  1.  
  2. if (value == "Ordered" || value == "Planned")
  3. {
  4.          document.myForm.myElement.readOnly = false;
  5. }
  6. else if (value != "Disposed")
  7. {
  8.          document.myForm.myElement.readOnly = true;
  9. }
  10.  
  11.  
Thanks,
Trupti
May 7 '10 #3
acoder
16,027 Expert Mod 8TB
You can't set a select element to read-only. Was that what you wanted to do?
May 7 '10 #4
@acoder
Yes, instead of disabling based on value in "value", which would not send the myElement on form submit, I thought I could make it readOnly.

Since according to you I cannot set it to readOnly like that, what I tried was to set it to disabled, but again enable it just before form submit. This ensured that the value of myElement was submitted. Not an optimum solution, but it works.

Do you have any other ideas?

Thanks,
Trupti
May 8 '10 #5
acoder
16,027 Expert Mod 8TB
Another way would be to hide the element and show it when required.
May 9 '10 #6
@acoder
Yes, which is what I'm doing effectively. Thank you very much for taking time out to reply to my query.

Trupti
May 9 '10 #7

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

Similar topics

1
by: Ittay Dror | last post by:
Hi, I have a form with various elements which, according to changes in values become enabled or disabled. The disabled elements are normally not submitted, but I wish they were. How can I go...
5
by: Dani | last post by:
Hello everybody, I have some code that disables form elements on body load, but I notice when I hit the "back" button, I need to re-enable the form elements (that is done by clicking on a radial...
12
by: Pudlik, Szymon | last post by:
Hi, I've written some code: function onSubmit(form){ for (var i = 0; i < form.elements.lenght; i++){ if (form.elements.disabled == 1) form.elements.disabled = 0; }
11
by: Jon Hoowes | last post by:
Hi, I have inherited some code that has some form elements (radio buttons) that are called "1", "2" etc. for example: <input name="2" type="radio" value="45"> <input name="2" type="radio"...
4
by: omidmottaghi | last post by:
I need to disable/enable form elements in my form. the code i was developed works fine in FF, but in IE, its behaviour is very strange!! in the form, we have a lot of checkboxes, all of them...
4
by: Mel | last post by:
how can i change disabled background on all form elements ?
1
by: gubbachchi | last post by:
Hi all, I have an issue here. There is a link "My plan" in the php page1. On clicking this link directs to a form which has some entries that has to be filled by the user.And once the user fills...
1
by: mikaint | last post by:
I've read that if a field is set to disabled, it will be excluded from the submited fields when sending a form. Is there an alternative way to disable a field but still, send it with the form? I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
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,...
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.