Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6594607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:49:59+00:00 2026-05-25T17:49:59+00:00

I have an HTML document with the following form: <form> <input type=text id=price> <input

  • 0

I have an HTML document with the following form:

<form>
    <input type="text" id="price">
    <input type="text" id="converted">
</form>

I also have the following JQuery:

$('#price').bind('keypress keyup', function() {
    amount = $(this).val() * 30;
    $('#converted').val(amount);
});

This works just as I want it to. If I type an amount in “price” then the value in “converted” is updated with whatever I typed, multiplied by 30.

However, I want this to support two different exchange rates, so I have created the following select in the form:

<select id="choice">
    <option value="1">Currency 1</option>
    <option value="2">Currency 2</option>
</select>

I know that I could set the values above to be the actual exchange rates and then this problem would be solved pretty quickly. However, I need the values to be the currency IDs for when the form is submitted. Therefore, I have made the following JSON object available:

[{"Currency":{"id":"1","rate":"30"}},{"Currency":{"id":"2","rate":"25"}}]

I have this available inline in the DOM because I don’t want to waste an ajax request every time new figures are typed in the input fields. The conversion doesn’t need to be THAT up-to-date. The above JSON object has been generated using CakePHP’s $javascript->Object and I can have it display either within script tags or any other way that would make it easily accessible to JQuery.

The part that I’m struggling with (and possibly can’t find on Google because I don’t know which terminology to use) is a way to use either ’30’ or ’25’ as the multiplier on the 2nd line of my JQuery depending on whether option value ‘1’ or ‘2’ is chosen in the select.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:50:00+00:00Added an answer on May 25, 2026 at 5:50 pm
    var json = [{"Currency":{"id":"1","rate":"30"}},{"Currency":{"id":"2","rate":"25"}}];
    
    $('#price').bind('keypress keyup', function() {
        var rate = $(json).filter(function() {
            return this.Currency.id == $('#choice').val();
        }).get(0).Currency.rate;
        var amount = $(this).val() * rate;    
        $('#converted').val(amount);
    });
    

    And here’s a live demo to see this in action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have something like this HTML structure : <form name=myvalue id=hello> <input type=text name=name
I have the following HTML <form id=create_form name=create_form action= method=post> <input name=type id=type value=individuel
I have the following function: <script type=text/javascript> function changeText(elem){ var oldHTML = document.getElementById(elem).innerHTML; var
I have the following HTML/JS/jQuery Code. This code represents a login form that is
I have the following problem: I have a form with three text input fields,
I have the following Jquery script: $(document).ready(function () { // When the submit button
i have the following javascript file named coupon.js - jQuery(document).ready(function(){ jQuery('.appnitro').submit( function() { $.ajax({
Hi I have a html form with the following code <td ><label> <textarea name=comments
I have the following form in a html5 document.I am a newbie as far
I have a small question about using jquery. I have the following code: <html>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.