Solved

A very simple program

Posted on 2000-03-23
6
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

730 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