WeLoveCSS Logo
Home Profile Members Search Rules Help New Posts



WeLoveCSS > PROGRAMMING LANGUAGES > Scripting and Server Side > Issue when pressing enter button.

Reply
  Thread Tools Display Modes
Old 18th May 13, 08:50 PM   #1
RhythmaticSoul
WLC Member
 
Join Date: Jul 2011
Posts: 7
Default Issue when pressing enter button.

Thank You...

I'm following along with a book recently purchased, but it doesn't address the issue of when the enter button is pushed the page reloads. Instead of doing the same command as when the Add Song button is click.

Here's the code I'm having issue's with:

<!doctype html>
<html lang="en">
<head>
<title>Add Songs</title>
<meta charset="utf-8">
<script>
window.onload = init;

function init(){
var button = document.getElementById("addButton");
button.onclick = handleButtonClick;
}//close init

function handleButtonClick(){
var songInput = document.getElementById("songInputText");
var songName = songInput.value;
songInput.innerHTML = songName;

var li = document.createElement("li");
li.innerHTML = songName;

var ul = document.getElementById("playlist");
ul.appendChild (li);


if (songName == ""){
alert("Please enter a song");
}//close if
}//close handleButtonClick
</script>
</head>

<body>
<form>
<input type="text" id="songInputText" size="40" placeholder="Song Name">
<input type="button" id="addButton" value="Add Song">
</form>

<ul id="playlist">

</ul>
</body>
</html>
RhythmaticSoul is offline   Reply With Quote
Old 18th May 13, 09:11 PM   #2
meesa
WLC Mod
 
meesa's Avatar
 
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,710
Default Re: Issue when pressing enter button.

Of course it doesn't. One bad thing about some books.

<form onsubmit="handleButtonClick();return false">
__________________
Praise be to the Lord God for the ability to learn, the capability to analyze, and the time to help users on this forum.
meesa is offline   Reply With Quote
Reply


Thread Tools
Display Modes
Linear Mode Linear Mode

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 12:07 AM.



Home | Advertise | Contact Us | Top
Home | Advertise | Contact Us | Top

Copyrightę 2006 WeLoveCSS.com. All Rights Reserved.
Powered by vBulletin Version 3.8.4 Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.