Click to See Complete Forum and Search --> : Problem with form code... n00b
I'm trying to use a form to add website addresses to a cell.
I have two text boxes (one for web site name, one for address) and a submit button.
I've given the button this code:
<input type="submit" value="Display" onClick="display();">
The text box for name is called web_name.
And I've added this code to the place where I want the website list:
<script language="JavaScript">
function display() {
message = "NAME: " + document.form1.web_name.value;
document.write(message);
}
</script>
This doesnt seem to work (no surprise) and even if it did would it allow me to list multiple addresses? Can anyone help?
David Harrison
07-01-2003, 04:51 PM
There's a thread (http://forums.webdeveloper.com/showthread.php?s=&threadid=12024) that I started, so that I could find the correct way of inserting writing into a div tag (just a way of adding page content after the page has loaded). I already have a non-correct way that works in everything but Netscape, but that's not the point.
If you were to position a div tag on your page where you wanted this address to appear, like so:
<div id="here"></div>
and then change your script to:
<script type="JavaScript">
function display() {
message = "NAME: " + document.form1.web_name.value;
here.innerHTML=message;
}
</script>
it should work for you, keep checking that other thread (http://forums.webdeveloper.com/showthread.php?s=&threadid=12024) to find out the correct way of doing this (ie: not using innerHTML).
Thanks but that doesnt seem to work :\
I've attached a version of my code without all the other html crap on the page.
Any ideas why it wont work? Im using IE 6
nkaisare
07-02-2003, 03:34 AM
you'll need document.getelementbyid(elementid).innerHTML = message.
I am not sure as I am an anti-javaite ;)
but document.write doesn't work once a page is rendered... you need to use innerHTML to change contents of any HTML element.
<head>
<script type="text/JavaScript">
function display() {
message = "NAME: " + document.form1.web_name.value;
document.getElementById('here').innerHTML = message;
}
</script>
</head>
<body>
<div id="here"></div>
<form name="form1" method="post" action="">
<p align="right"> Name:
<input type="text" name="web_name"></p>
<p align="right"> Address:
<input type="text" name="web_address"></p>
<p>
<input type="button" value="Display" onClick="display();">
</p>
</form>
</body>
i have change the submit button to a button as you are not submiting it to other place.