This topic is locked

How to disable/enable controls on Edit/Add pages

10/13/2007 7:36:18 AM
ASPRunnerPro Tips and tricks
admin

Add the following code to the end of Add/Edit page in Visual Editor in HTML mode.
This code snippet makes state dropdown disabled if other than US country is selected and define state field as required if US is selected as country.
Replace value_country and value_state with your own field names.
ASPRunnerPro 6.0



<script>

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

{

if(this.options[this.selectedIndex].value=='US')

{

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

define('value_state','IsRequired','State: ');

}

else

{

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

document.forms.editform.value_state.value='';

undefine('value_state');

}

}

function undefine(n)

{

if (document.editform != null)

{

for (i = 0; i < checkObjects.length; i++)

{

if (checkObjects[i].form.name==n)

checkObjects.splice(i,1);

}

}

}

</script>


ASPRunnerPro 6.1



<script>

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

{

if(this.options[this.selectedIndex].value=='US')

{

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

addValid.add(document.editform['value_State'],'IsRequired','State: ');

}

else

{

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

document.forms.editform.value_State.value='';

undefine('value_State');

}

}

function undefine(n)

{

if (document.editform != null)

{

for (i = 0; i < addValid.checkObjects.length; i++)

{

if (addValid.checkObjects[i][0].name==n)

{

var elem = addValid.checkObjects[i][0];

var par = $(elem).parent();

$('div',par).remove('.error');

addValid.checkObjects.splice(i,1);

}

}

}

}

</SCRIPT>
J
Jane 3/18/2010

Sample code for JavaScript Onload event on the Eventstab in ASPRunnerPro 6.2:



var tName = 'TableName';

var ctrlCountry = Runner.controls.ControlManager.getAt(tName, pageid, 'country');

var ctrlState = Runner.controls.ControlManager.getAt(tName, pageid, 'state');
ctrlCountry.on('change', function(e){

if (this.getValue() == 'US'){

ctrlState.setEnabled();

ctrlState.addValidation("IsRequired");

}else{

ctrlState.setDisabled();

ctrlState.setValue("");

ctrlState.removeValidation("IsRequired");

}

});
D
djscott76 3/18/2010

Now that 6.2 lets you Edit/Add master-details tables on the same page. Is there a script that would disable/enable detail tables, based on a field in the master table?

D
djscott76 3/19/2010



Sample code for ASPRunnerPro 6.2:

<script>

var tName = 'TableName';

var ctrlCountry = Runner.controls.ControlManager.getAt(tName, pageid, 'country');

var ctrlState = Runner.controls.ControlManager.getAt(tName, pageid, 'state');
ctrlCountry.on('change', function(e){

if (this.getValue() == 'US'){

ctrlState.setEnabled();

ctrlState.addValidation("IsRequired");

}else{

ctrlState.setDisabled();

ctrlState.setValue("");

ctrlState.removeValidation("IsRequired");

}

});

</script>



I tried to add the code, changing the following fields to match my database 'TableName', 'country', 'state', but it is not working for me. I tried pasting in the code at the end of the Add/Edit pages (through the html viewer) and I also tried to paste the code at the end of the head section of the Add/Edit pages. Is there something I am doing wrong? Is there another value that I was suppose to change?

J
Jane 5/5/2010

It's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

J
JOHNF777 11/10/2010

How does this work for ASPRunner 6.3 now?
Tried the same code but didn't work for me.\
Thanks in advance.

admin 11/10/2010

Version 6.3 works the same way as version 6.2 - Javascript API is the way to go.

S
StevePearce 3/13/2011

Hi,
Is it possible to do the above using radio buttons? I have tried to adapt the code with little success.
I am using ASPRunner 6.2 and am using the code in the OnLoad event.
Appreciate your help on this.
Thanks,

Steve

admin 3/14/2011

Steve,
hard to tell what might be wrong without seeing your files.
If you have a valid support contract post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.

C
CodeIsPoetry 2/29/2012



I tried to add the code, changing the following fields to match my database 'TableName', 'country', 'state', but it is not working for me. I tried pasting in the code at the end of the Add/Edit pages (through the html viewer) and I also tried to paste the code at the end of the head section of the Add/Edit pages. Is there something I am doing wrong? Is there another value that I was suppose to change?


same problem here. Dont work :S

admin 2/29/2012

CodeIsPoetry,
If you need help with this post your project to Demo Account and contact support directly. We'll be glad to assist.

C
CodeIsPoetry 3/15/2012



CodeIsPoetry,
If you need help with this post your project to Demo Account and contact support directly. We'll be glad to assist.


Problem solved.
You need to list all the values you use in the page. That values should be present.
Regards