/    Sign up×
Community /Pin to ProfileBookmark

Tricky form question need help

Hi

I have been bang my head on my desk trying to work out how to do this.
By the way not sure if i’ve posted my problem in the right place but here goes.

What i want to do is this

I have a form with 2 textfields

1 is called event the other description.

In the event textfield i want to make sure a user enters at least 2 words, if they enter 1 word or none then i want a message to come up telling them to enter 2 words.

Can anyone help

Thanks

Tony

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriNov 25.2004 — <head>
...
<script type="text/javascript">
function evalform() {
if(document.getElementById('field2').value.match('/ /i') || document.getElementById('field2').value.replace('/ /i', '') == "") {
return false;
} else {
return true;
}
</script>
...
</head>

<body>
<form onsubmit="return evalform();" ....>
<input type="text" name="field2" id="field2">
...
</form>
...
Copy linkTweet thisAlerts:
@cootheadNov 25.2004 — Hi there nelmest,

and here is another option...
[color=navy]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>minimum characters</title>

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />

<script type="text/javascript">
//<![CDATA[

function minLength(t,m) {

<i> </i>var l = t.value.length;

if (l &lt; m) {

<i> </i>alert("Your entry of " + l
<i> </i>+ " characters is less than the minimum of " + m + ".n"
<i> </i>+ "please go back and continue with your efforts.");

<i> </i>t.value = t.value.substring(0,m);

}
else {
document.forms[0].description.value="well done mate";
}
}

//]]&gt;
&lt;/script&gt;

&lt;/head&gt;
&lt;body onload="document.forms[0].event.focus()"&gt;

&lt;form action="#"&gt;
&lt;div&gt;
&lt;input type="text" name="event" onblur="minLength(this,2)"/&gt;
&lt;input type="text" name="description" /&gt;
&lt;/div&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

[/color]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@nelmestauthorNov 25.2004 — Thanks coothead that works really well for 2 letters but i wondered if you could help me do it for 2 words.

Thanks

Tony
Copy linkTweet thisAlerts:
@cootheadNov 25.2004 — Hi there nelmest,

I am sorry, but I misread your requirements :o :o :o

To make amends here is the [u]two word[/u] instead of [u]two letter[/u] version ?
[color=navy]&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;title&gt;minimum characters&lt;/title&gt;

&lt;meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /&gt;

&lt;script type="text/javascript"&gt;
//&lt;![CDATA[

function minLength(m) {

var pattern=document.forms[0].event.value;

if(pattern.search(/wsw/)==-1)

{

<i> </i>alert("Your entry of " + pattern
<i> </i>+ " is less than the minimum of " + m + " words.n"
<i> </i>+ "please go back and continue with your efforts.");

}
else {

<i> </i>document.forms[0].description.value="well done mate";

}
}

//]]&gt;
&lt;/script&gt;

&lt;/head&gt;
&lt;body onload="document.forms[0].event.focus()"&gt;

&lt;form action="#"&gt;
&lt;div&gt;
&lt;input type="text" name="event" onblur="minLength(2)"/&gt;
&lt;input type="text" name="description" /&gt;
&lt;/div&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
[/color]

[i]coothead[/i]
Copy linkTweet thisAlerts:
@nelmestauthorNov 25.2004 — Thank you very much coothead, very much appreciated.

Thanks

Tony
×

Success!

Help @nelmest 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 6.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

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