Spunky Posted June 7, 2011 Share Posted June 7, 2011 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 More sharing options...
Err Posted June 7, 2011 Share Posted June 7, 2011 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 More sharing options...
Ingolme Posted June 7, 2011 Share Posted June 7, 2011 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 More sharing options...
Spunky Posted June 7, 2011 Author Share Posted June 7, 2011 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 More sharing options...
ShadowMage Posted June 7, 2011 Share Posted June 7, 2011 I'm surprise the text box still showed with that missing 'e', thank you.The default type is text. The browser couldn't find a 'type' attribute, so it made it a text input. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.