|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
Use the "disabled" keyword in your form item. E.g.
Code:
<input type="text" name="foo" value="bar" disabled> |
|
#3
|
||||
|
||||
|
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.
|
|
#4
|
||||
|
||||
|
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. |
|
#5
|
||||
|
||||
|
Show us your JS so far.
|
|
#6
|
||||
|
||||
|
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. |
|
#7
|
||||
|
||||
|
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>
Let me know if the above code is alright. |
|
#8
|
||||
|
||||
|
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. |
|
#9
|
||||
|
||||
|
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.
|
|
#10
|
||||
|
||||
|
Just tested my theory - works like a charm!
|
|
#11
|
|||
|
|||
|
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 |
|
#12
|
|||
|
|||
|
Quote:
Google sent me too. Thanks for coming back and share what you found out. Saved my butt! |
|
#13
|
|||
|
|||
|
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 |
|
#14
|
|||
|
|||
|
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!
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Changing Readonly property using Javascript |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|