Scott
skipping stones Posts:8
|
02-27-2011 01:52 PM |
|
I am trying to get some very simple client side functionality to work. On my form, I have a dropdown menu that contains specific quantities of product that can be selected, and depending on the value of that dropdown, a shipping read-only field should auto-populate. The client side code I've written for the quantity dropdown menu is this:
$(txtShipping) = '$9.95'; if ($(lstQuantity) == '0') $(txtShipping) = ''; if ($(lstQuantity) == '2000') $(txtShipping) = '$19.90';
By default, the shipping field is blank. If I select any quantity option, the shipping field populates to "$9.95" as expected, and if I select the default "Select a Quantity" option the shipping field resets to nothing, again as expected. The problem comes when I select "2000" from the quantity dropdown; the shipping field should read "$19.90" but it instead reads "$9.95". It's as if the third line of JavaScript code above simply isn't getting read.
I've tried a variety of different approaches to the JavaScript, I've scoured the DataSprings Dynamic Forms forum (including the various demonstrations) and I just can't get this to work. Any suggestions? |
|
|
|
|
Ryan Bakerink
river guide Posts:1900
|
02-28-2011 08:57 AM |
|
Hello Scott,
Well first of all you don't want the txtShipping to be a string, but rather an integer so you can use this number for your calculations of the grand total.
Instead of referencing the token $(txtShipping) when ever you need the value, I would suggest assigning this to a variable.
Perhaps:
var theShipping = $(txtShipping);
Now the JavaScript statement you provided could look like this: ------------------------------------------------------------------------------- var theShipping = $(txtShipping); var lstQuantity = $(lstQuantity);
if(lstQuantity == '0') { theShipping = 0; }
if (lstQuantity == '2000') { theShipping = 19.90; }
-------------------------------------------------------------------------------
If you have any questions please let us know.
Thanks,
Ryan
|
|
|
|
|
Scott
skipping stones Posts:8
|
02-28-2011 06:22 PM |
|
Ryan, Thanks for the response. I did get the following code to work: var txtShipping = '9.95' var lstQuantity = $(lstQuantity); if(lstQuantity == '1139.90') { txtShipping = '19.90'; } if(lstQuantity == '1629.85') { txtShipping = '29.85'; } if(lstQuantity == '2489.75') { txtShipping = '49.75'; } if(lstQuantity == '4639.50') { txtShipping = '99.50'; } $(txtShipping) = txtShipping; $(txtTotal) = $(lstQuantity); $(txtDescription) = ' Sports Bands + $40 Art Setup Fee + $' + txtShipping + ' Shipping Fee'; Note that because I know what the shipping and setup fees will be based on quantity, I've embedded the final total into the Quantity dropdown control. The only problem now is that when I try to set the text of my Quantity dropdown to a value, it seems to wreck the entire client side computation. In other words, if I add the following line of code to the top: var txtQuantity = $(lstQuantity_Text); So I can end the computation with the following text (to be passed to Pay Pal): $(txtDescription) = txtQuantity + ' Sports Bands + $40 Art Setup Fee + $' + txtShipping + ' Shipping Fee' Then the entire client side computation fails. It's as if there is something wrong with the fetching of the text element associated with the Quantity dropdown menu. Am I referring to it incorrectly or something? |
|
|
|
|
Ryan Bakerink
river guide Posts:1900
|
03-01-2011 07:52 AM |
|
Hello Scott,
Try including your JavaScript under the Module Configuration -> Custom JavaScript File - > Initial JavaScript section.
Your computations are getting lost during the post back of the question event.
Please let me know if this helps you.
Thanks,
Ryan
|
|
|
|
|
Scott
skipping stones Posts:8
|
03-01-2011 03:37 PM |
|
Ryan, I think you're right. Not only am I losing my text description of the purchase when the form posts to PayPal, but if I purposely leave some mandatory fields unfillled and click the submit button, I lose my client-side completed fields when the form posts back to itself. So, I tried copying the JavaScript into the Custom JavaScript File section as you suggested (Initial JavaScript field), but no joy--I still lose my data. I also tried the Submit / Save JavaScript field, but that didn't work either. I noticed with the pre-supplied JavaScript examples that the fields I'm trying to auto-populate (identified with a $) seem to require the text "DynamicForms_" in front of the variable. So, for example, I changed in my code: var lstQuantity = $(lstQuantity); to... var lstQuantity = $(DynamicForms_lstQuantity); However, that didn't work either. It seems like no matter what I try, I can't get the client side JavaScript to work correctly when the form posts. Am I still doing something wrong? |
|
|
|
|