JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 27th, 2004, 11:30 PM
v_sharma77 v_sharma77 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 5 v_sharma77 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Changing Readonly property using Javascript

Hi,

I am using a table which contains text boxes. I need the text boxes to be read only untill one of the related text box is not populated by the user.
For Ex. I want the user to first fill the quantity and then other details. Unless the quantity is filled the text boxes containing other details sould remain read only.

Thanks in advance

Reply With Quote
  #2  
Old January 28th, 2004, 04:58 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Use the "disabled" keyword in your form item. E.g.
Code:
<input type="text" name="foo" value="bar" disabled>

Reply With Quote
  #3  
Old January 28th, 2004, 06:44 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
And as a companion to stumpy's suggestion, for any text box that governs others, call a function that takes a list of field names and sets those fields' disabled property to false upon entry of text into the governing text box.

Reply With Quote
  #4  
Old February 17th, 2004, 03:28 PM
sburcham's Avatar
sburcham sburcham is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 sburcham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Can you guys expand on this? I have the same issue, but no matter what I try I can't get it to work.

I have readonly in the input text field and my javascript looks at the value of another field. If the value in the "make" field is set to JD then I want the "model" field set to readonly, else let the user edit this field.

Reply With Quote
  #5  
Old February 17th, 2004, 06:33 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Show us your JS so far.
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #6  
Old February 18th, 2004, 02:50 PM
sburcham's Avatar
sburcham sburcham is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 sburcham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
JS -

function checkMake() {
if (document.newopp.make.value == "JD"){
newopp.model.diabled = true;
}
else {
newopp.model.disabled = false;
}
}

HTML -

<input class="main" type="text" name="model" size="15" value="" maxlength="30" OnFocus="focusCell('_model');checkMake();" OnBlur="blurCell('_model');" readonly>
-----

I have tried setting the js to newopp.model.readonly = true and how it is now. Neither seem to work.

Any help is greatly appreciated.

Reply With Quote
  #7  
Old February 18th, 2004, 04:31 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Try this (I've removed anything that wasn't required, and fixed up a few of your typo's)
Code:
<script type="text/javascript">
function checkMake() {
  if (document.newopp.make.value == "JD"){
    document.newopp.model.disabled = true;
  }
  else {
    document.newopp.model.disabled = false; 
  }
}
</script>
<form name="newopp">
<input type="text" name="make" value="JD">
<input type="text" name="model"  OnFocus="checkMake();" disabled>
</form>
Note that is is definately not a good idea to set any form items as disabled by default, as those users with JS turned off will not be able to correctly complete the form... unless of course if that is your intention.

Let me know if the above code is alright.

Reply With Quote
  #8  
Old February 19th, 2004, 08:50 AM
sburcham's Avatar
sburcham sburcham is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 sburcham User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That didn't do the trick. When the disabled keyword is used in the input field the field is disabled all of the time. If I leave the disabled keyword out then it seems to work. I have some other javascripts that run on the onFocus and onBlur that highlight and unhilight the row. I found a way to get that to work as well. When the field is disabled by the keyword then those js scripts did not work either.

Hopefully this is clear, if not I can try and clear it up further. Thanks for the help, it eventually lead to a solution.

Reply With Quote
  #9  
Old February 19th, 2004, 11:38 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Ok - just did a quick test - it's most likely not working because you can't give a disabled object focus... Makes sense. So, instead, put the checkMake function call on the "make" object, and fire it using the onBlur event.

Reply With Quote
  #10  
Old February 19th, 2004, 11:40 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 8 m 57 sec
Reputation Power: 9
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Just tested my theory - works like a charm!

Reply With Quote
  #11  
Old April 29th, 2005, 01:16 AM
bruceusername bruceusername is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 1 bruceusername User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 9 sec
Reputation Power: 0
Google sent me.
The above code is good, but i want to know if it's possible to do it with the "readonly" attribute instead of "disabled".
anyone know?

edit: yes, only readonly is spelt readOnly

Last edited by bruceusername : April 29th, 2005 at 01:23 AM. Reason: only

Reply With Quote
  #12  
Old August 29th, 2006, 07:01 PM
sweimh sweimh is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 sweimh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 45 sec
Reputation Power: 0
Quote:
Originally Posted by bruceusername
Google sent me.
The above code is good, but i want to know if it's possible to do it with the "readonly" attribute instead of "disabled".
anyone know?

edit: yes, only readonly is spelt readOnly


Google sent me too.
Thanks for coming back and share what you found out.
Saved my butt!

Reply With Quote
  #13  
Old November 1st, 2007, 12:07 PM
jaeagle jaeagle is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 1 jaeagle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 49 sec
Reputation Power: 0
not sure if anyone will still be looking at this but can any of you help

i am trying to do the same as above but rather that a text box having a value in it i am after a set of radio buttons to do the same job any help would be great

Reply With Quote
  #14  
Old September 20th, 2008, 05:20 PM
malcolmnew malcolmnew is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 2 malcolmnew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 33 sec
Reputation Power: 0
Smile Another Approach

The problem with disabled and readonly is that they wont be reenabled - at least I cannot get them to do so. I have solved the problem by using style.visibility = 'hidden' | 'visible' and style.display = 'none' | 'block' (or whatever). This works and I don't see the point of knocking ones head against a brick wall!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Changing Readonly property using Javascript


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |