Jump to content

.innerHTML


Spunky

Recommended Posts

HTML code:

<form name="engWordForm" onsubmit="engToJap()" id="engForm">		<fieldset>			<legend>Enter English Word</legend>			<input typ="text" name="wordInput" id="wordInput" />			<input type="submit" value="Enter" />		</fieldset>	</form><div id="wordDisplay">		<p id="wordArea">Test</p></div>

Javascript code:

function engToJap() {	var i;	var wordValue = document.forms["engWordForm"]["wordInput"].value;	for (i=0;i<engWords.length;i++) {		if (engWords[i]==wordValue) {			alert(japWords[i].valueOf());			document.getElementById("wordArea").innerHTML=japWords[i].valueOf();			break;		}	}	if (i==engWords.length){		alert("Word does not exist!");	}}

engWords and japWords are arrays.When I click the submit, the text in "wordArea" changes accordingly for about a split second and then changes back.

Link to comment
Share on other sites

Don't know if it will help but you're missing an 'e' on 'type' for type="text"

Link to comment
Share on other sites

The page is reloading due to the form being sent. Add "return false;" to the onsumbit handler:onsubmit="engToJap(); return false;"

Link to comment
Share on other sites

Don't know if it will help but you're missing an 'e' on 'type' for type="text"
I'm surprise the text box still showed with that missing 'e', thank you.
The page is reloading due to the form being sent. Add "return false;" to the onsumbit handler:onsubmit="engToJap(); return false;"
Fixed, thank you. Forgot about the form reloading like that.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...