aspose file tools*
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
Author

Readonly fields...setting dynamically

Tokunbo Oke
Ranch Hand

Joined: Sep 09, 2003
Posts: 57
Background
==========

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() {
document.forms[0].customerNo.readonly=false;
document.forms[0].regDate.readonly=false;
}
</SCRIPT>

Function call
=============
<SCRIPT language="JavaScript">
enablefields();
</SCRIPT>


FULL SOURCE
===========


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

<table width="500" border="0">
<tr>
<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>
</tr>
<tr>
<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>
</tr>
<tr>
<td>Dob(DD/MON/YYYY):</td>
<td><input type="text" name="dob" value=""></td>
<td>Sex:</td>
<td><select name="sex" size="1"><option value="M">Male</option>
<option value="F">Female</option>
<option value=""></option></select>
</td>
</tr>
<tr>
<td>Address:</td>
<td><textarea name="address" rows="4"></textarea></td>
<td>Address Code:</td>
<td><input type="text" name="addressCode" size="10" value=""></td>
</tr>
<tr>
<td height="37">Email:</td>
<td><input type="text" name="email" value=""></td>
<td>Phone:</td>
<td><input type="text" name="phone" value=""></td>
<td>Fax:</td>
<td><input type="text" name="fax" value=""></td>
</tr>
<tr>
<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></select>

<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>

</td></select>
</tr>
</table>
<br>
<bR>

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

<SCRIPT>function set(target) {
document.forms[0].action=target;
}
</SCRIPT>



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



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





</body>
</html>
Eric Pascarello
author
Rancher

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

.readOnly =

the little thing that causes it to not to work.

Eric
Tokunbo Oke
Ranch Hand

Joined: Sep 09, 2003
Posts: 57
Eric,

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: http://aspose.com/file-tools
 
subject: Readonly fields...setting dynamically