This topic is locked

How to change field to readonly/disabled via Edit Event

6/13/2008 5:24:49 AM
PHPRunner General questions
J
jack knowles author

Hi Forum,
I've got a field called job_category in my suppliers table.
How can i set the job_category field to be readonly/disabled on the Edit page, Before record updated Event via the script below:
=='Yes') {

set job_category field to readonly

}else{

unset job_category field to readonly}


Thanks
JK

J
Jane 6/17/2008

Hi,
use JavaScript to change field on the fly.

Here is a sample:

{literal}<script>

document.forms.editform.value_employment_approved.onchange=function()

{

if(document.forms.editform.value_employment_approved.value=='Yes')

document.forms.editform.value_job_category.disabled=true;

else

document.forms.editform.value_job_category.disabled=false;

}

</script>{/literal}


To add JavaScript code turn on HTML mode on the Visual Editor tab.

D
dunga 6/24/2008

hi, Jane

I have similar question:
how to disable rest of the form fileds if selected value is YES?

and where exactly to add this lines of sample code (literals/javascripts)you recommended?Please
my idea is to have 3 or more fields disabled unless YES for one of the forms had been chosen.
thank you again.

J
Jane 6/25/2008

Hi,
To add JavaScript code turn on HTML mode on the Visual Editor tab. You can add this code at the end of page.
Here is just a sample:

{literal}<script>

document.forms.editform.value_employment_approved.onchange=function()

{

if(document.forms.editform.value_employment_approved.value=='Yes')

{

document.forms.editform.value_fieldname1.disabled=true;

document.forms.editform.value_fieldname2.disabled=true;

document.forms.editform.value_fieldname3.disabled=true;

}

else

{

document.forms.editform.value_fieldname1.disabled=false;

document.forms.editform.value_fieldname2.disabled=false;

document.forms.editform.value_fieldname3.disabled=false;

}

}

</script>{/literal}

S
steveh 6/27/2008

Do you have an example of doing this in php using smarty rather than javascript?

J
Jane 6/30/2008

No. PHP is executed on the server, JavaScript is executed on the client side.

S
steveh 6/30/2008

Understand that, but if, before the page is displayed I want to change that field to read only (i.e. have it just as a display element rather than a field), is there a way to tell smarty to do this in the event before the page is displayed?