select () and focus()

Hi,

I齧 not shure, if this is right here.

My problem is the following code

<html>

<head>

<title>MMDE 5 zweite Aufgabe</title>

<script language=JavaScript><!--

function CheckInput(){

//var eingabe=document.formular.mail.value;

if(document.formular.mail.value.indexOf('@') == -1){

alert("Die Eingabe ist keine g齦tige e-mail-Adresse");

document.formular.mail.select();

}else {

alert("Danke f齬 die Registrierung! Bald erhalten Sie unseren Newsletter!");

document.formular.mail.focus();

}}

//--></script>

</head>

<body>

<center>

<font size="5"><b>Infos ohne langes Suchen. </b></font>

Geben Sie uns einfach Ihre e-mail-Adresse und Sie erhalten regelm齭sig unseren Newsletter mit den neuesten Informationen!

<form name="formular" action="mailto:wuzon@t-online.de" method="post">

Ihre e-mail Adresse:

<input type="text" name="mail" size="30">

<input type="submit" name="Button" value="Abschicken" onClick="CheckInput()">

</center>

</form>

</body>

</html>

When I press the "Abschicken"-Button the function "CheckInput" is supposed to run (check the input, if it齭 an valid e-mail-adress continue with sending the data, else show the alert-window an after press the button in the alert-window mark the wrong adress). My problem is now, the input is checked, but the data will be send in every case and the checked input isn齮 marked at all.

Please help me!! I齧 confused! Where齭 my error?Thx!

[1703 byte] By [Wuzon] at [2007-9-30 21:03:50]
# 1

> Hi,

> I齧 not shure, if this is right here.

> My problem is the following code

>

> <html>

> <head>

> <title>MMDE 5 zweite Aufgabe</title>

> <script language=JavaScript><!--

> function CheckInput(){

> //var eingabe=document.formular.mail.value;

> if(document.formular.mail.value.indexOf('@') == -1){

> alert("Die Eingabe ist keine g齦tige e-mail-Adresse");

> document.formular.mail.select();

> }else {

> alert("Danke f齬 die Registrierung! Bald erhalten Sie

> unseren Newsletter!");

> document.formular.mail.focus();

> }}

> //--></script>

> </head>

> <body>

> <center>

>

> <font size="5"><b>Infos ohne langes Suchen.

> </b></font>

>

> Geben Sie uns einfach Ihre e-mail-Adresse und Sie

> erhalten regelm齭sig unseren Newsletter mit den

> neuesten Informationen!

>

> <form name="formular"

&gt; action="mailto:wuzon@t-online.de" method="post">

> Ihre e-mail Adresse:

> <input type="text" name="mail" size="30">

> <input type="submit" name="Button" value="Abschicken"

&gt; onClick="CheckInput()">

> </center>

> </form>

> </body>

> </html>

>

> When I press the "Abschicken"-Button the function

> "CheckInput" is supposed to run (check the input, if

> it齭 an valid e-mail-adress continue with sending the

> data, else show the alert-window an after press the

> button in the alert-window mark the wrong adress). My

> problem is now, the input is checked, but the data

> will be send in every case and the checked input isn齮

> marked at all.

>

> Please help me!! I齧 confused! Where齭 my error?Thx!

Hi there,

Well this is a JavaScript question as opposed to Java, so you're asking in the wrong forums :-). However, I think I have the answer for you, you need to add <b>return false;</b> This should stop the Submit continuing after the JavaScript call.

Hope that helps!

Karianna

karianna at 2007-7-7 2:35:47 > top of Java-index,Archived Forums,Debugging Tools and Techniques...