The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Need help with simple form
MakeMineA99
post Sep 19 2014, 10:14 AM
Post #1





Group: Members
Posts: 2
Joined: 19-September 14
Member No.: 21,568



Hi there,

Need a little help. I am trying to do something very simple that is proving to be tricky. I need a form that, when you enter a Zip Code, no matter the Zip Code, it just displays a generic message below the input area of "Congratulations!...". Here is what I am working with:

<html>
<head lang="en">
<meta charset="UTF-8">
<script language="JavaScript">
function showInput() {
var message_entered = document.getElementById("user_input").value;

document.getElementById('display').innerHTML = message_entered;
}

</script>

</head>
<body>

<form>
<input type="text" name="message" id="user_input">
</form>

<input type="submit" onclick="showInput();"><br />
<p><span id='display'></span> </p>
</body>
</html>

Can anyone help me finish this to do what I need it to do? Any help is much appreciated.

This post has been edited by MakeMineA99: Sep 19 2014, 10:28 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
pandy
post Sep 19 2014, 11:34 AM
Post #2


🌟Computer says no🌟
********

Group: WDG Moderators
Posts: 20,730
Joined: 9-August 06
Member No.: 6



You mean you want to display the zip together with a message? Just add the message to the innerHTML line. Note that the text needs to be quoted and the variable cannot be, so you need to split it up in two parts like below.

CODE
document.getElementById('display').innerHTML = 'Congratulations ' + message_entered;


Or three even if you want the zip in the middle of the message.

CODE
document.getElementById('display').innerHTML = 'Congratulations ' + message_entered +'!';
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
MakeMineA99
post Sep 19 2014, 11:56 AM
Post #3





Group: Members
Posts: 2
Joined: 19-September 14
Member No.: 21,568



Works like a charm. Thank you kindly! I really appreciate it!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Sep 19 2014, 12:33 PM
Post #4


.
********

Group: WDG Moderators
Posts: 9,653
Joined: 10-August 06
Member No.: 7



As a side note, you don't need the <form> and </form> start and end tags just for this javascript. But if you want to submit a form to a server side script, the submit button must be inside the form too.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 19th April 2024 - 02:07 AM