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 8809041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:46:21+00:00 2026-06-14T02:46:21+00:00

I am trying to write a short piece of html code that, given two

  • 0

I am trying to write a short piece of html code that, given two initial amounts, attempts to find the number greater than or equal to the first that wholly divides the second given amount. The code tries to divide the numbers, and if it is unsuccessful, adds 1 to the first number and tries to divide again, etc…

I want the code to return the value that does wholly divide the second number AND the answer to the division (with some plain text appearing around it).

Added to this, or at least I’d like there to be, is that upon clicking one of 5 different buttons a multiplication operation is performed on the first given number, it is rounded up to the nearest whole number, and THEN the function attempts to divide this into the second given number.

It’s difficult to explain exactly what I want without showing you the code I have so far, so here it is:


<html>

<head>

<b>Rounded Commodity Pricing:</b><br>

<script language="Javascript">

function finddivid(marketprice,tradevalue) { 

var KWDex = 0.281955
var GBPex = 0.625907
var USDex = 1
var CADex = 0.998727
var EURex = 0.784594

if 
  (currency == "KWD") 
  var currencyMarketprice = Math.ceil(marketprice*KWDex)
else if
  (currency == "GBP")
  var currencyMarketprice = Math.ceil(marketprice*GBPex)
else if 
  (currency == "USD") 
  var currencyMarketprice = Math.ceil(marketprice*USDex)
else if 
  (currency == "CAD") 
  var currencyMarketprice = Math.ceil(marketprice*CADex)
else if 
  (currency == "EUR") 
  var currencyMarketprice = Math.ceil(marketprice*EURex)


if (tradevalue % currencyMarketprice == 0)
  return ("tonnage = " + tradevalue / currencyMarketprice + " mt, and price = " + currencyMarketprice +" " +currency +" per mt");
else
  {for (var counter = currencyMarketprice+1; counter<(currencyMarketprice*2); counter++) {
   if (tradevalue % counter == 0)
     return ("tonnage = " + tradevalue / counter + " mt, and price = " + counter +" " +currency +" per mt");}}};

</script>

</head>

<p>Select currency:
<input type="button" value="KWD" OnClick="var currency = KWD">
<input type="button" value="USD" OnClick="var currency = USD">
<input type="button" value="GBP" OnClick="var currency = GBP">
<input type="button" value="EUR" OnClick="var currency = EUR">
<input type="button" value="CAD" OnClick="var currency = CAD">

<P>Enter today's price of commodity in USD: <input name="mktprc" input type="number"><br><p>
<P>Enter value of trade: <input name="trdval" input type="number">

<input type="button" value="Calculate" OnClick="showMeArea.value=finddivid(mktprc,trdval);">

<p>
<br><br>

<input name="showMeArea" readonly="true" size="30">

</html>

If you run this html in your browser you should see what I am trying to achieve.

It is far from complete but here are the main problems/features that I need help with:

  1. I would like to be able to click on one of the ‘currency’ buttons so that upon clicking, the variable ‘currency’ is assigned and then used in the function finddivid.

(2. This isn’t as important right now, but eventually, once this is working, I’d like it so that upon clicking one of the currency buttons, it changes colour, or is highlighted or something so that the user knows which currency rate they are using.)

  1. Upon entering the numbers into the two boxes I would like to click ‘Calculate’ and have it return what I’ve written in the function into the ‘showMeArea’ read-only box at the end of the code.

I know I’m probably missing loads of stuff and I might be miles away from success but I am very new to programming (started 4 days ago!) so would like any like of help that can be offered.

Thanks in advance of your comments.

  • 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-06-14T02:46:22+00:00Added an answer on June 14, 2026 at 2:46 am

    The first request requires that you put the currency into the actual script, and I would recommend using a setter function:

    <script language="Javascript">
    
    var currency;   // you might want to set this at a default just in case
    
    function setCurrency(val) { currency = val; }    // Setter function
    
    function finddivid(marketprice,tradevalue) { 
    

    Then call it in your button click:

    <input type="button" value="KWD" onClick="setCurrency('KWD');">
    

    As for the second request, I’d say you have the concept down well enough, but you don’t have the method exactly right. First your inputs will need an id attribute:

    <input name="mktprc" id="mktprc" input type="number">
    <input name="trdval" id="trdval" input type="number">
    

    The name attribute is used for posting values, the id attribute is used by javascript to find elements within a page. Using jQuery would make retrieving these elements easy, but I’ll show both the jQuery and the standard JavaScript method of doing this:

    jQuery:

    <input type="button" value="Calculate" OnClick="$('#showMeArea').val(finddivid($('#mktprc'),$(#'trdval')));">
    

    The $('#id') selects an element. The method .val() sets the value.
    Note for the jQuery purists: Yes, there are much better/sophisticated ways to accomplish this with jQuery, but this answer is targeted to my perception of OP’s JavaScript capability.

    Standard Javascript:

    <input type="button" value="Calculate" OnClick="document.getElementById('showMeArea').value = finddivid(document.getElementById('mktprc'),document.getElementById('trdval'));">
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a short function that will let me quickly read in
I'm trying to write a short Wordpress JQuery for Wordpress comments that would allow
In short: Trying to write a wcf service for a winform-app that invokes a
I am trying to write a short function that will take a cell of
Long story short: I'm trying to write an app that'll dump IE's history to
I am trying to write code that will loop through all cells in a
I'm trying to write a short script that will query my mysql db, and
I'm trying to write a piece of software that allows one to click on
I am trying to develop a piece of code in Java, that will be
Trying to write a short method so that I can parse a string and

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.