document.write from a textbox
Posted: Mon Nov 09, 2009 7:07 am
I'm pretty new to JavaScript and struggling with document.write
It's possible to create a response box to collect data and then use document.write to return this to the existing page.
Is it possible to similarly collect data from a textbox and add that without the page reloading and losing the existing html, stylesheets etc?
e.g. As a trivial example, can I use document.write to add this to the existing body or do I have to use an innerhtml call to do this?
<head>
<script type="text/javascript">
function getText()
{
var mytext = document.getElementById('input1');
document.write(mytext.value);
}
</script>
</head>
<body>
<input type="text" name="input1" id="input1" onblur="getText()" >
</body>
I'm also struggling to understand when and why you sometimes, but not always, seem to need to add .value after the variable as in (mytext.value)
Any advice very welcome!
J
It's possible to create a response box to collect data and then use document.write to return this to the existing page.
Is it possible to similarly collect data from a textbox and add that without the page reloading and losing the existing html, stylesheets etc?
e.g. As a trivial example, can I use document.write to add this to the existing body or do I have to use an innerhtml call to do this?
<head>
<script type="text/javascript">
function getText()
{
var mytext = document.getElementById('input1');
document.write(mytext.value);
}
</script>
</head>
<body>
<input type="text" name="input1" id="input1" onblur="getText()" >
</body>
I'm also struggling to understand when and why you sometimes, but not always, seem to need to add .value after the variable as in (mytext.value)
Any advice very welcome!
J