Hello,
I am trying to put up a page for my students for them to be able to enter
their class number into a field and instantly get a personalized text
message. (ie student number 5 enters "5" and gets a message like
"Congratulations on your homerun in Kickball Bobby!"
Can this be done using a form and if so would that be the best way to do it?
Any help would be greatly appreciated! 5 2207
kw wrote: Hello,
I am trying to put up a page for my students for them to be able to enter their class number into a field and instantly get a personalized text message. (ie student number 5 enters "5" and gets a message like "Congratulations on your homerun in Kickball Bobby!"
Can this be done using a form and if so would that be the best way to do it? Any help would be greatly appreciated!
<script type="text/javascript">
var customMessages = [
null,
'This is message one',
'This is message two',
'This is message three',
'This is message four',
'This is message five'
];
function setMessage(inp) {
var idx = +inp.value;
if (!isNaN(idx) && idx > 0 && customMessages[idx]) {
inp.form.output.value = customMessages[idx];
} else {
inp.form.output.value = '';
}
}
</script>
<form>
<input type="text" name="class_number" size="3" maxlength="3"
onchange="setMessage(this);" />
<br />
<input type="text" name="output" readonly="readonly" style="border:none;"
onfocus="this.blur();" tabindex="-1" />
</form>
The above is the simplest way to do it with the widest range of browser support.
<url: http://jibbering.com/faq/#FAQ4_15 /> provides a way to modify the content
of a <span> or <div> in an existing page if you feel you want to tackle that.
--
| Grant Wagner <gw*****@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
* http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
* http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
kw said: Hello,
I am trying to put up a page for my students for them to be able to enter their class number into a field and instantly get a personalized text message. (ie student number 5 enters "5" and gets a message like "Congratulations on your homerun in Kickball Bobby!"
Can this be done using a form and if so would that be the best way to do it? Any help would be greatly appreciated!
I would do it like this.
It's pretty easy to update, and you can have a personalized
greeting for every student without having to think of something
completely original for each one. Be careful about commas when
you make changes, and be sure to test it before your students do.
<html>
<head>
<script type="text/javascript">
msg = [
// Double-quotes around names and around messages.
// Any double-quotes inside the messages must be \"escaped\"
// You can use %name% anywhere in the message.
// It's ok to skip numbers that don't match any student.
1, "Abe", "Welcome to our school, Abe!",
2, "Jan", "Jan, Please say hello to your sister Marcia for me!",
3, "Peter", "Hello, %name%!",
5, "Bobby", "Congratulations on your homerun in kickball, Bobby!",
6, "Ted", "Hello, %name%!",
7, "Jim", "Hello, %name%!",
8, "Sue", "Hello, %name%!",
9, "Bob", "Hello, %name%!",
10, "Joe", "Hello, %name%!",
12, "Kim", "Hi, %name%. I've always liked the name, \"%name%\"!",
14, "Zoe", "Hi, %name%. I've always liked the name, \"%name%\"!"
// No comma at the end of the last message!
// When you add names to the end, remember to add a
// comma to the message that used to be last.
];
function greet(id){
id=id.replace(/\s*/g,""); // remove any accidental spaces
for(var i=0;i<msg.length;i+=3){
if(msg[i]==id){
var greeting=msg[i+2].replace(/%name%/g,msg[i+1]);
alert(greeting);
return;
}
}
alert("I think you made a mistake.\n"+
"I don't know student number \""+id+"\".");
}
</script>
</head>
<body>
<form onsubmit="return false"> <!-- don't really submit this form to the server
-->
Type your student number here: <input name="id" size="4"><br>
Then press the "Hello" button: <input type="button"
value="Hello"
onclick="greet(this.form.id.value)">
</form>
</body>
</html>
"Lee" <RE**************@cox.net> wrote in message
news:c8*********@drn.newsguy.com... kw said: Hello,
I am trying to put up a page for my students for them to be able to enter their class number into a field and instantly get a personalized text message. (ie student number 5 enters "5" and gets a message like "Congratulations on your homerun in Kickball Bobby!"
Can this be done using a form and if so would that be the best way to do
it?Any help would be greatly appreciated! I would do it like this. It's pretty easy to update, and you can have a personalized greeting for every student without having to think of something completely original for each one. Be careful about commas when you make changes, and be sure to test it before your students do.
<html> <head> <script type="text/javascript">
msg = [
// Double-quotes around names and around messages. // Any double-quotes inside the messages must be \"escaped\" // You can use %name% anywhere in the message. // It's ok to skip numbers that don't match any student.
1, "Abe", "Welcome to our school, Abe!", 2, "Jan", "Jan, Please say hello to your sister Marcia for
me!", 3, "Peter", "Hello, %name%!", 5, "Bobby", "Congratulations on your homerun in kickball,
Bobby!", 6, "Ted", "Hello, %name%!", 7, "Jim", "Hello, %name%!", 8, "Sue", "Hello, %name%!", 9, "Bob", "Hello, %name%!", 10, "Joe", "Hello, %name%!", 12, "Kim", "Hi, %name%. I've always liked the name,
\"%name%\"!", 14, "Zoe", "Hi, %name%. I've always liked the name,
\"%name%\"!" // No comma at the end of the last message! // When you add names to the end, remember to add a // comma to the message that used to be last.
];
function greet(id){ id=id.replace(/\s*/g,""); // remove any accidental spaces for(var i=0;i<msg.length;i+=3){ if(msg[i]==id){ var greeting=msg[i+2].replace(/%name%/g,msg[i+1]); alert(greeting); return; } } alert("I think you made a mistake.\n"+ "I don't know student number \""+id+"\"."); } </script> </head> <body> <form onsubmit="return false"> <!-- don't really submit this form to the
server --> Type your student number here: <input name="id" size="4"><br> Then press the "Hello" button: <input type="button" value="Hello" onclick="greet(this.form.id.value)"> </form> </body> </html>
That works perfectly. Thank you so much I really appreciate it!
(Thank you too Grant!)
In article <c8*********@drn.newsguy.com>, Lee
<RE**************@cox.net> wrote:
<snip> 1, "Abe", "Welcome to our school, Abe!", 2, "Jan", "Jan, Please say hello to your sister Marcia for me!", 3, "Peter", "Hello, %name%!", 5, "Bobby", "Congratulations on your homerun in kickball, Bobby!", 6, "Ted", "Hello, %name%!", 7, "Jim", "Hello, %name%!", 8, "Sue", "Hello, %name%!", 9, "Bob", "Hello, %name%!", 10, "Joe", "Hello, %name%!", 12, "Kim", "Hi, %name%. I've always liked the name, \"%name%\"!", 14, "Zoe", "Hi, %name%. I've always liked the name, \"%name%\"!"
<snip>
Since the messages are unique to each student number, why separate out
the name? Your idea is great if there was a set of messages and the
message number is used in each entry.
message[1] = "Hello, %name%!"
6, "Ted", 1,
etc.
--
Dennis Marks http://www.dcs-chico.com/~denmarks/
To reply change none to dcsi.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =----- http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Dennis Marks said: In article <c8*********@drn.newsguy.com>, Lee <RE**************@cox.net> wrote:
<snip> 1, "Abe", "Welcome to our school, Abe!", 2, "Jan", "Jan, Please say hello to your sister Marcia for me!", 3, "Peter", "Hello, %name%!", 5, "Bobby", "Congratulations on your homerun in kickball, Bobby!", 6, "Ted", "Hello, %name%!", 7, "Jim", "Hello, %name%!", 8, "Sue", "Hello, %name%!", 9, "Bob", "Hello, %name%!", 10, "Joe", "Hello, %name%!", 12, "Kim", "Hi, %name%. I've always liked the name, \"%name%\"!", 14, "Zoe", "Hi, %name%. I've always liked the name, \"%name%\"!" <snip>
Since the messages are unique to each student number, why separate out the name? Your idea is great if there was a set of messages and the message number is used in each entry.
message[1] = "Hello, %name%!"
6, "Ted", 1,
Ease of maintenance is one of the most important factors in
this design. I specifically wanted the message to be typed
right next to the student's name, despite the redundancy.
You don't want to accidentally congratulate the wrong student
because you got their numbers mixed up.
An alternative that I considered was to have an array of
constructor calls, (or even literal Objects) such as:
msg = [
new Greeting(1, "Bobby", "Congratulations!"),
new Greeting(3, "Sue"),
new Greeting(4, "Jim")
]
Which would make it easier to have a default greeting, but it
seemed like it was adding more sources of error.
Note that in either design, you could define some standard messages
and replace the literal string messages with variable names:
var default = "Hello, %name%!";
var tardy = "Late again, %name%?"; This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: da Vinci |
last post by:
OK, this has got to be a simple one and yet I cannot find the answer
in my textbook.
How can I get a simple pause after an output line, that simply waits
for any key to be pressed to move on?
...
|
by: hoover_richard |
last post by:
I am a newbie to C++ and I need help with a simple program I am trying
to write. My program is designed to print all of the odd integers
contained in an array and output the sum of the odd...
|
by: jmac |
last post by:
Greetings fellow programmers,
I have created a C program that has a few bugs and would like to get
some help with working them out. Here is a list of the problems that
I am experiencing:
-...
|
by: Paul |
last post by:
I want to make a simple calculator program but dont know where to get
started. This is not GUI but a simple terminal program.
It would get input like this
Enter number:
5
+
10
|
by: Just starting out |
last post by:
I am very new to C code and I'm having a lot of trouble with a homework
assignment.
This program is supposed to take the amount of Euros that the user
enters and convert it to US dollars.
It...
|
by: Buck Rogers |
last post by:
Hi all! Newbie here.
Below is an example from Teach Yourself C in 21 Days. My apologies
if it is a bit long.
What I don't understand is how the "get_data" function can call the...
|
by: cnoobie |
last post by:
Problem 1 - Min, Mean, Max
Write a program that reads in successive integer values from the user. The user will indicate termination of these values with the sentinel value 0 (zero). After the...
|
by: Kayvine |
last post by:
Hi guys, this is a question I have for an assignment, it is pretty long, but I am not asking for the code(well if someone wants to write I'll be really happy, lol), but I just want to know how to...
|
by: just curious |
last post by:
Create a C++ console application that uses a while loop to count, total, and average a series of positive integers entered by a user. The user enters a –1 to signal the end of data input and to...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |