Solved

A very simple program

Posted on 2000-03-23
6
168 Views
Last Modified: 2006-11-17
I want to submit a user name and display an alert message if the user does not enter his name, I don't know what is the problem in my code:
-----------------------------------
<script language="JavaScript">

function test(Name){
  if (isNaN(Name)){
    alert("You must enter your name");}
else
  alert("Hello " + Name);
}

</script>

<form name="form1" onSumbit=test(this.edit1.value)>
<input type="text" name=edit1>
<input type=submit value="Submit" name=B1>
</form>
------------------------

Azzoz
0
Comment
Question by:Azzoz
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:binkzz
ID: 2648450
Your test function will need to return false,

so use this instead:

<script language="JavaScript">

function test(Name)
{
  if (isNaN(Name))
  {
    alert("You must enter your name");
    return false;
  } else
  {
    alert("Hello " + Name);
    return true;
  }
}

</script>

<form name="form1" onSumbit=test(this.edit1.value)>
<input type="text" name=edit1>
<input type=submit value="Submit" name=B1>
</form>
0
 
LVL 3

Expert Comment

by:bigbed
ID: 2648513
Its a bit strange to use isNaN(), since I don't think a name will be a number!

Why not use:
if (name == "")
{
  alert ( "You must enter name" )
  return false;
}
etc.
0
 

Author Comment

by:Azzoz
ID: 2648575
It didn't work
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 4

Accepted Solution

by:
binkzz earned 50 total points
ID: 2648589
<form name="form1" onSumbit=check(document.form1.edit1)>
<input type="text" name=edit1>
<input type=submit value="Submit" name=B1>
</form>

<script language=javascript>
  function check(what)
  {
    var value = what.value;

    if (value == '')
    {
      alert ('Please enter a name');
      what.focus();
      return false;
    }
  }
</script>



Try that, and what browser are you using?
0
 

Author Comment

by:Azzoz
ID: 2648654
Thanks Binkzz, it works,

by the way I write Sumbit instead of Submit.

Did you really begin programming since you were 8 years old?? and which language did you start with?

Azzoz
www.geocities.com/motaz1
0
 
LVL 4

Expert Comment

by:binkzz
ID: 2648659
I started with VBasic on the Commodore 64, but when I was a bit older my grandfather started teaching me Turbo Pascal 3.0 on a CP/M system.

It all went from there really :)
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question