Xenonsoft
Active Member
I'm just learning javascript and getting my head around it but there's a simple problem I've encountered.
Using document.write within a function that doesn't specify where to write it seems to fail.
I'm starting at the basics and I'm trying to have get the input from an input box and simply write it, after the submit button has been clicked.
The code I've got at the moment (which doesn't work):
<head>
<script type="text/javascript">
function print_number()
{
var num = document.getElementById('input-number').value;
document.write(num);
}
</script>
</head>
<body>
<form>
Put your high number in here: <input type="text" id="input-number" />
<input type="button" value="submit" onclick="print_number()" />
</form>
</body>
I think the problem is that it doesn't know where to write the new variable?
Worth noting it works as an alert, but that's not quite what I'm after.
Using document.write within a function that doesn't specify where to write it seems to fail.
I'm starting at the basics and I'm trying to have get the input from an input box and simply write it, after the submit button has been clicked.
The code I've got at the moment (which doesn't work):
<head>
<script type="text/javascript">
function print_number()
{
var num = document.getElementById('input-number').value;
document.write(num);
}
</script>
</head>
<body>
<form>
Put your high number in here: <input type="text" id="input-number" />
<input type="button" value="submit" onclick="print_number()" />
</form>
</body>
I think the problem is that it doesn't know where to write the new variable?
Worth noting it works as an alert, but that's not quite what I'm after.