• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Readonly fields...setting dynamically

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you need to capitalize the O

.readOnly =

the little thing that causes it to not to work.

Eric
 
Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic