Link to home
Start Free TrialLog in
Avatar of infodigger
infodigger

asked on

Pass a value from javascript to c#

I need to retrieve a value calculated using javascript back to my c# code.

The javascript code is here:

      function calculateShipping(){            
            var numberTotal = new NumberFormat( parseFloat(Shipping.value) + parseFloat(subTotal) );
            numberTotal.setPlaces(2);
            
            totalPrice.innerHTML = baseCurrency + numberTotal.toFormatted();
      }

I need to pass the numerTotal back to c# when an imagebutton is clicked on a page.

Thanks!!
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
One possible way is with an AJAX Call...

Make AJAX call a page, eg:

www.yoursite.com/getvalue.aspx?myvalue=1234

Where:

"getvalue.aspx" is a c# page to retreive your JS value
"myvalue" is the POST variable to hold your value
"1234" is your POST value

Have AJAX call that page, but do not bother to display it. I do this method with PHP quite often, if you like I can pull out the code I use for this to help you along.

Hope that helps.
And after further reading Zvonko's reply, I see her mentioned the same thing... sorry Zvonko :o)
No problem :)
Avatar of infodigger
infodigger

ASKER

Thank you all for your help!
You are welcome.