
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2019 04:17 PM
I am trying to write an onChange client script to make a select box field in a catalog item display a specific choice when another select box variable is chosen on the item. If a specific shipping address is selected, I need the company name to change to a different name. I have about 5 company names and 10 shipping addresses, so I set the company name field to default to the standard name and would like it to change if one of the other shipping addresses is selected. My Ship to variables are quite long so wanted to use "startsWith".
My script is not working and since I'm quite new to scripting I have been trying to cobble together something based on other community posts and Googling. I'd appreciate some assistance!
Here is my script so far:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Change the company name if necessary
var ship=g_form.getValue('ship_to');
if (ship.startsWith('TX'));
{
g_form.setValue('company_name','Texas Company');
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2019 09:19 AM
I got some help from someone in our company who is way better at js than I am and this is what he came up with that works.
Then after the first case repeated the values for any other sites that needed the company name changed, otherwise the "default" company name was used.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Change the company name if necessary
var ship_value = g_form.getValue('ship_to');
switch(ship_value)
{
case 'TX':
g_form.setValue('company_name',"Acme Corp");
g_form.setValue('tax_id', '00000000');
break;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2019 06:12 PM
Try
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Change the company name if necessary
var ship=g_form.getValue('ship_to').toString();
alert(ship); //See what you are getting in the alert.
if (ship.startsWith('TX'));
{
g_form.setValue('company_name','Texas Company');
}
}
Please mark my response as correct and helpful if it helped solved your question.
-Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2019 10:06 AM
Thank you Prateek, unfortunately it still isn't working and oddly, I'm not even getting the alert to show!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2019 10:42 AM
HI,
Can you use below script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Change the company name if necessary
var ship=g_form.getDisplayBox('ship_to').value;;
alert(ship); //See what you are getting in the alert.
if (ship.startsWith('TX'));
{
g_form.setValue('company_name','Texas Company');
}
}
Thanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-07-2019 09:19 AM
I got some help from someone in our company who is way better at js than I am and this is what he came up with that works.
Then after the first case repeated the values for any other sites that needed the company name changed, otherwise the "default" company name was used.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Change the company name if necessary
var ship_value = g_form.getValue('ship_to');
switch(ship_value)
{
case 'TX':
g_form.setValue('company_name',"Acme Corp");
g_form.setValue('tax_id', '00000000');
break;