Solved

A very simple program

Posted on 2000-03-23
6
167 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
rhino JavaScript import, load 25 67
Sums of coloumns in html/java 15 67
Google Map JavaScript API 4 40
Angular.js example vocabulary extensions 5 34
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

911 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

15 Experts available now in Live!

Get 1:1 Help Now