Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have a HTML/JavaScript page for e

Status
Not open for further replies.

Deltaflyer

Programmer
Oct 11, 2000
184
GB
I have a HTML/JavaScript page for editing records in my databases, this works ok. For functionality reasons i need to be able to lock this page if the record that is being edited has been completed.

I.E. if the COMPDATE field has an entry then all the fields on my editrecord.asp are read-only.

I have the following code to make a field permanently read-only,

<form name=form>
<input type=text name=box value=&quot;ReadOnly&quot; onChange=&quot;this.value='ReadOnly';&quot; size=12 readonly></form>

what i would like is to be able to make a field read-only via javascript, dependant on if the COMPDATE field has an entry.
DeltaFlyer - The Only Programmer To Crash With Style.
 
Stupid netscape cut off half my message, as i was saying :

i have looked around a lot of JavaScript Archives with no luck, if anyone knows how or where i could find this coding then i would really appreciate it.

Thanx, DeltaFlyer DeltaFlyer - The Only Programmer To Crash With Style.
 
Dear DeltaFlyer,

This works in IE 5... Good luck

-pete


<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--

function FName_onchange() {
var s = new String(window.event.srcElement.value);
if ( s.length > 0){
document.form1.Birthday.readOnly = false;
document.form1.Birthday.value = &quot;&quot;;
}
else{
document.form1.Birthday.readOnly = true;
document.form1.Birthday.value = &quot;Read Only&quot;;
}
}

//-->
</SCRIPT>
<form name=&quot;form1&quot; >
<input type=&quot;text&quot; name=&quot;FName&quot; LANGUAGE=javascript onchange=&quot;return FName_onchange()&quot;><br>
<input type=&quot;text&quot; name=&quot;Birthday&quot; value=&quot;Read Only&quot; readonly>
 
palbano, cheers for that i will try out your coding but i do need something that works in netscape as well, unfortunately most of the people that will be using this page will be using netscape. |-I

(Why did they write that, it's awful, IE5 isn't brilliant but at least it pretends to act intelligently, netscape has the intelligence of an old boot.):-(

Thank for your response, DeltaFlyer DeltaFlyer - The Only Programmer To Crash With Style.
 
if you prevented people to type in the field, would this do the trick ?
if yes then use the blur() function when people focus on your field
<input type=text name=box onfocus=&quot;javascript:this.blur()&quot; value=&quot;whatever&quot;>
this works both in ie and ns and the input field acts as if it was read only
hope that helps ...
 
The BLUR() function is a valid option, however somtimes i want to be able to edit the field and sometimes not.

I would prefer not to have to write the entire page based around a HUGE IF statement, i.e.

If compdate <> &quot;&quot; Then
Field1=readonly & onfocus=blur
Field2=readonly & onfocus=blur
Else
Field1=read/write
Field2=read/write
End If


If this is the only way i can do it then that is the way i must do it, but i would prefer to call a JavaScript that sets all fields readonly if i want to and doesn't if i don't.

Thanks for the response,;-) DeltaFlyer DeltaFlyer - The Only Programmer To Crash With Style.
 
in that case just write a jscript function that sets all the input type you want as read only, and one that unsets this ?
something like :
function set_all() {
// say you want ALL the input type=text elements to be read only
for (i=0; i<your_form.elements.lenght; i++)
if (your_form.elements.type==&quot;text&quot;)
your_form.elements.onfocus=&quot;blur()&quot;;
}

is that helping ??
 
Dunno yet, but i'll sure give it a go. DeltaFlyer ;-)

DeltaFlyer - The Only Programmer To Crash With Style.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top