I am working on currency converter, its a school project, I have done the assignment and done with it.
<HTML>
<HEAD>
<TITLE>Currency Converter Protype1</TITLE>
</HEAD>
<BODY>
<SECTION>
<P>Enter Amount:
<INPUT type="number" ID="Val" list="CommonVal">
<Datalist ID="CommonVal">
<option value=1>1</option>
<option value=10>10</option>
<option value=100>100</option>
<option value=500>500</option>
</Datalist>
<Select id="Select">
<Option Value=1 name=1 >AUS</Option>
<Option Value=82 name="Japanese Yen">Yen</Option>
<Option Value=5 name="Chinese Yaun">Yaun</Option>
<Option Value=10000 name="Indonesian Rupiah">Rupiah</Option>
</Select>
<Button ID="Submit" onclick="Process()">Click Me</Button>
</P>
</SECTION>
<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">
function Process() { // Module 2
var val = document.getElementById("Val").value;
var Select = document.getElementById("Select").value * 1;
var country = ["Australia", "Japanese Yen", "Chinese Yuan", "Indonesian Rupiah"];
var rate = [1, 82, 5, 100000];
var text = "";
var i;
for (i = 0; i < country.length; i++) {
text += country[i] + ": $ " + (((val*1)/Select)*rate[i]).toFixed(2) + "<br>";
}
document.getElementById("Country1").innerHTML = text;
}
//(val/select)*() "Australia", "Japanese Yen", "Chinese Yen", "Indonesian Rupiah"
</SCRIPT>
<p id="Country1"></p>
</BODY>
</HTML>
And being done ahead of time, I managed to do that, but I want to do better than that. So instead I thought of working more on it. Now I want my code to take in a value of an input box and display it another input box. But the problem is that I cant set constants to input. For example, setting the country1 to some numerical value. But I don't know how to do it.
<HTML>
<HEAD>
<TITLE>Currency Converter Protype1</TITLE>
</HEAD>
<BODY>
<SECTION>
<P>Enter Amount:<br> Australia:
<INPUT type="number" name="country1" ID="Val" list="CommonVal" oninput="Process()"><br> Japanese Yen:
<INPUT type="number" name="country2" ID="Val" list="CommonVal" oninput="Process()"><br> Chinese Yaun:
<INPUT type="number" name="country3" ID="Val" list="CommonVal" oninput="Process()"><br> Indonesian Rupiah:
<INPUT type="number" name="country4" ID="Val" list="CommonVal" oninput="Process()"><br>
<Datalist ID="CommonVal">
<option value=1>1</option>
<option value=10>10</option>
<option value=100>100</option>
<option value=500>500</option>
</Datalist>
</P>
</SECTION>
<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">
var
function Process() { // Module 2
var val = document.getElementById("Val").value;
var Select = document.getElementById("Select").value * 1;
var country = {
"Australia": 1,
"Japanese Yen": 82,
"Chinese Yuan": 5,
"Indonesian Rupiah": 10000
};
var text = "";
var i;
var b;
for (var i in country) {
text += i + ": " + (((val * 1) / Select) * country[i]).toFixed(2) + "<br />";
}
document.getElementById("Country1").innerHTML = text
}
</SCRIPT>
<p id="Country1"></p>
</BODY>
</HTML>
The result should show the values when any value in the country is inputted. I was told that to print out a value in the input box, the document.getElementById().value = …; Can be used.