Forums: How to disable/enable controls on Edit/Add pages - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to disable/enable controls on Edit/Add pages based on another control value

#1 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 13749
  • Joined: 03-February 03

Posted 13 October 2007 - 11:36 AM

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>

Best regards,
Sergey Kornilov
0

#2 User is offline   Jane 

  • Advanced Member
  • PipPipPip
  • Group: Admin
  • Posts: 7495
  • Joined: 13-June 06

Posted 18 March 2010 - 10:51 AM

Sample code for Javascript onload event on the Events tab 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");
     }
});

best regards,
Jane Endaltseva
e-mail: support@xlinesoft.com
0

#3 User is offline   Scott Smith 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 12-May 09

Posted 18 March 2010 - 08:58 PM

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?
0

#4 User is offline   Scott Smith 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 4
  • Joined: 12-May 09

Posted 19 March 2010 - 11:16 AM

View PostJane, on 18 March 2010 - 05:51 AM, said:

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?
0

#5 User is offline   Jane 

  • Advanced Member
  • PipPipPip
  • Group: Admin
  • Posts: 7495
  • Joined: 13-June 06

Posted 05 May 2010 - 01:05 PM

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.
best regards,
Jane Endaltseva
e-mail: support@xlinesoft.com
0

#6 User is offline   johnf777 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 45
  • Joined: 29-November 06

Posted 10 November 2010 - 10:49 PM

How does this work for ASPRunner 6.3 now?

Tried the same code but didn't work for me.\

Thanks in advance.
0

#7 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 13749
  • Joined: 03-February 03

Posted 11 November 2010 - 03:33 AM

Version 6.3 works the same way as version 6.2 - Javascript API is the way to go.
Best regards,
Sergey Kornilov
0

#8 User is offline   Steven Pearce 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 23-August 10

Posted 13 March 2011 - 03:07 PM

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
0

#9 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 13749
  • Joined: 03-February 03

Posted 14 March 2011 - 04:40 PM

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.
Best regards,
Sergey Kornilov
0

#10 User is offline   CodeIsPoetry 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 18-January 11

Post icon  Posted 29 February 2012 - 10:43 AM

View PostScott Smith, on 19 March 2010 - 11:16 AM, said:

View PostJane, on 18 March 2010 - 05:51 AM, said:

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?


same problem here. Dont work :S
0

#11 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 13749
  • Joined: 03-February 03

Posted 29 February 2012 - 02:25 PM

CodeIsPoetry,

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

#12 User is offline   CodeIsPoetry 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 7
  • Joined: 18-January 11

Posted 15 March 2012 - 11:40 AM

View Postadmin, on 29 February 2012 - 02:25 PM, said:

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
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic