php - Call Javascript Function Based on Radio Button Checked Value -


i have form sets default values based on user's account settings (stored in mysql db , pulled using php). when form displayed, pulls relevant account information , populates form (first name, last name, email, account type, etc.)

when user's account type 'admin' want rest of form become disabled, , have options selected. if user's account type 'admin', , therefore 'edit_type_admin' radio button checked default (see below) call makeeditdisable() function below page loaded (without requiring clicks).

right form displays account type follows:

client or admin: <br /> client <input type="radio" name="edit_type" id="edit_type_client" value="client" <? if($selected_type == 'client') { echo 'checked'; } ?> onclick="makeeditenable()" /> admin <input type="radio" name="edit_type" id="edit_type_admin" value="admin" <? if($selected_type == 'admin') { echo 'checked'; } ?> onclick="makeeditdisable()" /> 

when toggling between 2 options onclick makeeditenable()/makeeditdisable() functions work correctly:

<script type="text/javascript">           function makeeditdisable(){               var x=document.getelementbyid("edit_access_begin")               x.disabled=true;               var x=document.getelementbyid("edit_access_expire")               x.disabled=true;               var x=document.getelementbyid("edit_project_access_yes")               x.checked=true;               var x=document.getelementbyid("edit_project_access_yes")               x.disabled=true;               var x=document.getelementbyid("edit_project_access_no")               x.disabled=true           }          function makeeditenable(){             var x=document.getelementbyid("edit_access_begin")             x.disabled=false;             var x=document.getelementbyid("edit_access_expire")             x.disabled=false;             var x=document.getelementbyid("edit_project_access_yes")             x.disabled=false;             var x=document.getelementbyid("edit_project_access_no")             x.disabled=false          }</script> 

add script or function loads after elements have loaded, , of course after makeeditdisable() has loaded:

<? if($selected_type == 'admin') { echo 'makeeditdisable();'; } ?> 

this should call function.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -