postoak Posted December 24, 2014 Share Posted December 24, 2014 When I run the following code and submit, the page flashes (about 1 second) with the modified html and then disappears. Is it something to do with the function? <!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><title>Learning Java Script</title></head><body><form id="choice" onsubmit="decision();">Logo or text? <input type="text" id="c1"><input type="submit" value="Enter"></form><p id="display"></p><script>function decision() {var answer = document.getElementById("choice").value;var replace = document.getElementById("display");if (answer === "text") {replace.innerHTML = document.createTextNode("<p>some text</p>");}else {replace.innerHTML = document.createTextNode("<img src="gr8oz2.0.png" alt="">");}return false;}</script></body></html> Link to comment Share on other sites More sharing options...
Ingolme Posted December 24, 2014 Share Posted December 24, 2014 Sicne you're using an event attribute (not a good idea) you have to put return false inside the attribute itself. <form id="choice" onsubmit="decision(); return false"> 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now