/    Sign up×
Community /Pin to ProfileBookmark

Error handling help needed

Hi,

I have a very simple form which has name and number text already inserted upon the load of the page. I would like the user to input their name and number, and then click submit, however I have found that many users are simply clikcing the submit button.

This means that we are receving emails with name and number only.

How can I make ther user input something here, and stop the form from processing if nothing, ior name and number are inserted.

Thank you.

Mark

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@mhouldridgeauthorJul 19.2004 — Here is the source;

<form name="form3" method="post" action="process3.asp">

<input name=name id=domainmain43

style="FONT-SIZE: 11px; FONT-FAMILY: Verdana" value="name and number" size=19 onClick="this.value=''">

<INPUT name=Submit24 type=submit style="FONT-SIZE: 10px; FONT-FAMILY: Verdana" value=request>

</form>
Copy linkTweet thisAlerts:
@KorJul 19.2004 — You need a verifying code, try this:

[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
function verify(){
d=document.forms['form3'].elements['name']
if((d.value.length<1)||(d.value=='name and number')){
alert('Please insert your Name and Number!');
d.focus()
return false
}
}
</script>

</head>

<body>
<form name="form3" method="post" action="process3.asp" onsubmit="return verify()">
<input name=name id=domainmain43
style="FONT-SIZE: 11px; FONT-FAMILY: Verdana" value="name and number" size=19 onClick="this.value=''">
<INPUT name=Submit24 type=submit style="FONT-SIZE: 10px; FONT-FAMILY: Verdana" value=request>
</form>
</body>
</html>
[/code]


It will verify if the text field is empty [b]or[/b] if the field has his genuine value ('name and number'). If so, alert, focus the field and stop the submit process (using conditioned [b]return false[/b])
Copy linkTweet thisAlerts:
@javaNoobieJul 19.2004 — might wanna try this...

<script language = javascript>

function validate(){

var i;

i = domainmain43.value;

if((i == "") || (i=="name and number")){

alert("Please Enter A Value");

return false;

}

}

</script>

on your submit button..

<INPUT name=Submit24 type=submit style="FONT-SIZE: 10px; FONT-FAMILY: Verdana" value=request onclick="validate()">

hope this helps..
Copy linkTweet thisAlerts:
@mhouldridgeauthorJul 19.2004 — Excellent - you are a star... it's working perfectly now.
Copy linkTweet thisAlerts:
@KorJul 19.2004 — Welcome to the Forum, JavaNoobie, but, be careful, your variant has 4 big mistakes:

  • 1. The validate function has to be handled by [b]onsubmit[/b] event, not by [b]onclick[/b]. Otherwise the function will be fired onclick, than [b] in any case [/b] the submit action will be starded, because they are two different events. Thus, the handler should be placed in FORMS tag, onsubmit event, NOT in button onclick.


  • 2. If you use return false/true contitioner you should call it in handler


  • onevent="[color=red]return[/color] verify()"

  • 3. The "short-cut" reference as

    element_name.[i]attribute[/i]


  • will work only for IE and it is not a recomanded practice. You should use the full reference

    document.form_name.element_name.[i]attribute[/i]

    (or, if case, the parameter [b]this[/b] or [b]this.form[/b] in handler)

  • 4. You were not attentive. You should have check the text field value, named [b]name[/b] not the buttons value named [b]domainmain43[/b].


  • So, you should have wrote:

    i = document.forms['form3'].element['name'].value

    Eventually you should have wrote the same code I did...

    ?

    Take care
    Copy linkTweet thisAlerts:
    @steelersfan88Jul 19.2004 — [i]Originally posted by Kor [/i]

    [B]Eventually you should have wrote the same code I did...

    ? [/B]
    [/QUOTE]
    Well, one could also include the return tru, hence different. I, for one, make my conditions like, if(something == something_else) ... you did not include the spaces.

    But the real only difference is the paramater, making it easier to reference the form.

    The real point of this post, though ... to the original poster: All attributes of any element should be enclosed in double quotes ("). the only exceptions that could exist are numbers, such as height and width of images.

    Dr. Script
    Copy linkTweet thisAlerts:
    @KorJul 20.2004 — {quote]

    one could also include the return tru

    [/quote]

    Yes, if you want to keep the books strict rules but also the book says that return true is the default boolean, so you may not write it.
    ×

    Success!

    Help @mhouldridge spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.5,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...