Alternative for document.write ?
I have a simple calculator here that takes the number of songs from the input text box and multiplies it by 500 and then tells you the total. I am doing this on a simple web page for a project for college. I know document.write overwrites my entire page to print the result but I would like to keep the page and design that I have made and to print the result on the same paragraph as where the script and text box are.
x = *document.form1.inputbox.value;
var numrix, numriy;
document.writeln("The price of "+x+" songs is "+res+" euros");
You didn't supply your <form> so this is a guess...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
x = document.form1.inputbox.value,
y = 500,
numrix = parseInt(0 + x, 10);
numriy = parseInt(y, 10);
res = numrix * numriy;
document.getElementById('result').innerHTML = "The price of " + numrix + " songs is " + res + " euros";
<input type="text" name="inputbox" onkeyup="kalkulo();" />
thnx for the effort m8
In general you normally assign an id to a container on your page where you want the output to appear and then assign the output to the container's innerHTML, value or whatever is appropriate property.
Originally Posted by ghforces
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)