WeLoveCSS Logo
Home Profile Members Search Rules Help New Posts

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

  Thread Tools Display Modes
Old 18th May 13, 09:50 PM   #1
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">
<title>Add Songs</title>
<meta charset="utf-8">
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

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

<ul id="playlist">

RhythmaticSoul is offline   Reply With Quote
Old 18th May 13, 10:11 PM   #2
meesa's Avatar
Join Date: Jul 2009
Location: Milky Way Galaxy
Posts: 3,714
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

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 07:27 PM.

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 - 2018, Jelsoft Enterprises Ltd.