Issue with readonly text field and JavaScript function -
11-04-2005
, 08:44 PM
I have an ASP that I load from a database table. Several fields are date
fields. If the date field has a value in the table, I make the input field
readonly to prevent the users from overwriting the stored data. However, I
have a single date field at the top of the form that I need to use to allow
a user to apply that date to all date fields on the form, except for the
readonly ones. I cannot seem to get this to work. If I use the disabled
attribute in the text field and in the script below, it works fine... but I
can't disable the text fields because I cannot then post data from them to
the database. Here's the script:
function apply_date_all(theForm){
//apply date in txtdateall box to every date field on page except readonly
ones
var dateval = theForm.txtDateForAll.value;
if (dateval == ""){return false}
var len = theForm.length;
for(i=0;i<len;i++){
if(theForm.elements[i].type == "text"){ //if its a text field
if(theForm.elements[i].name.substring(0,9) == "userdate_"){
if(theForm.elements[i].readonly == false){
theForm.elements[i].value = dateval;
}
}
}
}
}
Basically, I need to disallow updates to the readonly fields via Javascript,
but allow updates to the fields that are NOT readonly. Can anyone see the
problem in my script?
Thanks for the assistance.
Julian |