Solved

A very simple program

Posted on 2000-03-23
6
166 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
Comment Utility
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
Comment Utility
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
Comment Utility
It didn't work
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 4

Accepted Solution

by:
binkzz earned 50 total points
Comment Utility
<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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now