...

View Full Version : can someone tell my why this Javascript coding does not work



Tallyho
06-17-2008, 09:50 AM
Hi I'm reposting my coding problem as i still cannot get it to work. As i'm new to all this it's probably something very simpler that's missing but anyhelp would be appreciated. Her is my origianl message;

i have to create some coding that prompts a user to enter their selection from 1 - 3 selcting 3will terminate the programme and so far i have managed to get that bit to work. Now i have to create code that, when a user delects 1 i have to store their details ie firstname last name age etc. This is where i need help, the code i am using is as follows but it does not work;
language="JavaScript"
type="text/javascript">

var readerForename;
var readerSurname;
var readerName;
var readerAge, ageDiff;
var password;
var option;
option = 0;

document.write('COUNTY LIBARARIES'+'<BR>'+
'============================='+'<BR>'+
'What would you like to do?'+'<BR>'+
'<OL>'+
'<LI>'+'Register as a reader'+'</LI>'+
'<LI>'+'View your details'+'</LI>'+
'<LI>'+'Exit'+'</LI>'+
'</OL>'+
'Enter 1, 2 or 3 to select'+'<BR>')

while (option != 3)
{
option = window.prompt('Please select an option between 1 and 3.','');
option = parseFloat(option);
while (option < 1 || option > 3)
{
option = window.prompt('You must select an option between 1 and 3.','');
option = parseFloat(option);
}
}
document.write('<BR>'+'GOODBYE ');
if (option == 1)
{
readerForename = window.prompt('Please enter your forename ','');
readerSurname = window.prompt('Please enter your surname ', '');
readerAge = window.prompt('Please enter your age ', '');
readerAge = parseFloat(readerAge);
}
if (readerAge < 5 || readerAge > 120)
{
readerAge = window.prompt('Please re enter your age ', '');
readerAge = parseFloat(readerAge);
}
if (readerAge < 5)
{
ageDiff = (5 - readerAge)
document.write('Sorry. You are too young. Come back in ' + ageDiff + ' year.');
}
else
{
document.write('<BR>'+'Thank you, ' + readerForename + ' ' + readerSurname + '.' + ' You are now a member of the Library.');
}

can someone please help????

Philip M
06-17-2008, 11:55 AM
You do not seem to have taken the slightest notice of the answer you were given before. Do have a look at the posting guidelines re silly thread titles, using the code tags etc. And in English the personal pronoun I is spelled with a capital I. Why make it hard for yourself?

language="JavaScript"
type="text/javascript"> does not help.

You need a </script> tag.

This is working but needs quite a lot of tidying up:-



<script type = "text/javascript">

var readerForename;
var readerSurname;
var readerName;
var readerAge, ageDiff;
var password;
var option;
option = 0;

document.write('COUNTY LIBARARIES'+'<BR>'+
'============================='+'<BR>'+
'What would you like to do?'+'<BR>'+
'<OL>'+
'<LI>'+'Register as a reader'+'</LI>'+
'<LI>'+'View your details'+'</LI>'+
'<LI>'+'Exit'+'</LI>'+
'</OL>'+
'Enter 1, 2 or 3 to select'+'<BR>')


option = window.prompt('Please select an option between 1 and 3.','');
option = parseInt(option);
while (option < 1 || option > 3)
{
option = window.prompt('You must select an option between 1 and 3.','');
option = parseInt(option);
}

if (option == 3) {
document.write('<BR>'+'GOODBYE ');
}

if (option == 1)
{
readerForename = window.prompt('Please enter your forename ','');
readerSurname = window.prompt('Please enter your surname ', '');
readerAge = window.prompt('Please enter your age ', '');
readerAge = parseInt(readerAge);
}
if (readerAge < 5 || readerAge > 120)
{
readerAge = window.prompt('Please re enter your age ', '');
readerAge = parseInt(readerAge);
}
if (readerAge < 5)
{
ageDiff = (5 - readerAge)
document.write('Sorry. You are too young. Come back in ' + ageDiff + ' year.');
}
else if (option ==1) {
{
document.write('<BR>'+'Thank you, ' + readerForename + ' ' + readerSurname + '.' + ' You are now a member of the Library.');
}
}
</script>


One more time, you cannot "store" their details except using a server-side language. OK?

Tallyho
06-17-2008, 02:16 PM
I'm sorry we seem to have gotten off to a bad start Philip M, but I did look at the post you kindly directed me to however, the replies (other than yours), seemed to focus on the one and only part of the code that I could get working I also took time to read the notes on 'silly thread titles' and thought that my current thread title was more appropriate although you seem to disagree.

Can I finally say that there really is no need for you to be so brash, no one else seems to find my lack of understanding and ability irritating and as such i will apologise to you again and find another forum where they may be a bit more 'forgiving' to older people such as myself.

Philip M
06-17-2008, 02:29 PM
I also took time to read the notes on 'silly thread titles' and thought that my current thread title was more appropriate although you seem to disagree.


Once more, please realise that the thread title is supposed to help people who have a similar problem in future. Can you not see that yours is useless for this purpose? Every post amounts to "Help! Why does my code not work?"

Sorry you have taken the hump, but I did take the time and trouble to get your code to work - more than anyone else bothered to do.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum