File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Readonly fields...setting dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Readonly fields...setting dynamically" Watch "Readonly fields...setting dynamically" New topic

Readonly fields...setting dynamically

Tokunbo Oke
Ranch Hand

Joined: Sep 09, 2003
Posts: 57

I have a field in my form which is a readonly field. I Have a method to conditionally set this field to readable at runtime. I cannot figure out why this function set the fields to readable when called. Please help!
The function is below:

Function definition
<SCRIPT language="JavaScript">function enablefields() {

Function call
<SCRIPT language="JavaScript">


<form name="cargoForm" method="post" action="/cargo/" onsubmit="return confirmDelete('');">

<table width="500" border="0">
<td width="54">Customer No:</td>
<td width="37"><input type="text" name="customerNo" maxlength="5" size="5" value="" readonly="readonly"></td>
<td width="59">Reg Date:</td>
<td width="92"><input type="text" name="regDate" value="" readonly="readonly"></td>
<td width="64">First Name:</td>
<td width="37"><input type="text" name="firstName" value=""></td>
<td width="55">Last Name:</td>
<td width="68"><input type="text" name="lastName" value=""></td>
<td><input type="text" name="dob" value=""></td>
<td><select name="sex" size="1"><option value="M">Male</option>
<option value="F">Female</option>
<option value=""></option></select>
<td><textarea name="address" rows="4"></textarea></td>
<td>Address Code:</td>
<td><input type="text" name="addressCode" size="10" value=""></td>
<td height="37">Email:</td>
<td><input type="text" name="email" value=""></td>
<td><input type="text" name="phone" value=""></td>
<td><input type="text" name="fax" value=""></td>
<td >Status:</td>

<td ><select name="status" size="1"><option value="A">ACTIVE</option>
<option value="I">INACTIVE</option>
<option value="S">SUSPENDED</option>
<option value=""></option>


<td width="64">Credit Rating:</td>

<td ><select name="creditRating" size="1"><option value="E">EXCELLENT</option>
<option value="V">VERY GOOD</option>
<option value="G">GOOD</option>
<option value="P">POOR</option>
<option value="B">BAD</option>
<option value=""></option>


<SCRIPT>function confirmDelete(instruction) {
if (document.forms[0].action==instruction){
return ( window.confirm("Are you sure?") );
else{ return true;

<SCRIPT>function set(target) {

<SCRIPT language=javascript>enablefields()</SCRIPT>

<input type="submit" value="Save" on click="set('');">
<input type="submit" value="Get Customer" on click="bCancel=true; set('')">
<input type="submit" value="Delete Customer" on click="set('')">
<input type="submit" name="org.apache.struts.taglib.html.CANCEL" value="Cancel" on click="set('')">

Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
you need to capitalize the O

.readOnly =

the little thing that causes it to not to work.

Tokunbo Oke
Ranch Hand

Joined: Sep 09, 2003
Posts: 57

Thank you very much indeed! It now works! I did not realise that Javascript is case sensitive - I have to find time to learn this language.
I agree. Here's the link:
subject: Readonly fields...setting dynamically
jQuery in Action, 3rd edition