onChange client script-get old value of choice field

matthew_magee1
Giga Guru

Hi all-

Trying to find a way, using a client script to get the previous value of a choice field before it is changed and without saving the form

Example:

User opens form

User has to select a value from 'Division' (CID, MDD, MED, ISB)

User selects CID

alert> ''

User then selects MDD

alert> 'CID'

User then selects ISB

alert> 'MDD'

I think this is doable via jquery but not 100% sure

 

Any help is greatly appreciated

1 ACCEPTED SOLUTION

Using the g_scratchpad object may be better in this case.  I've been trying to find a good article to reference but it's difficult now that the Wiki is gone.

 

Basically, you can use "g_scratchpad.variable_name = newValue" to keep the value updated.

View solution in original post

4 REPLIES 4

Kunal Jha
Giga Expert

Please share your code . Are you trying to use newValue ?

jamy2
Tera Contributor

Try This:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}

//Type appropriate comment here, and begin script below

alert("The default value is " + oldValue);
alert("The New value is" + newValue);
}

HI Jamy,

 

Unfortunately oldValue/newValue won't work because oldValue is only what was saved to the DB. I want to get the old value w/out saving to the DB.

 

I did find a solution.

I created a hidden field called 'u_hidden_division'.

I populate this field w/ the value from Divisions.

So coming into the form, u_hidden_division is blank

If I change Division, I have an onChange client script that will take the value of u_division and populate u_hidden_division

If I change Division again, i can throw in an alert that will show me the value of the new value of u_division and the 'old' value stored in u_hidden_division.

 

I particularly don't like creating new fields, but this works.

Using the g_scratchpad object may be better in this case.  I've been trying to find a good article to reference but it's difficult now that the Wiki is gone.

 

Basically, you can use "g_scratchpad.variable_name = newValue" to keep the value updated.