/    Sign up×
Community /Pin to ProfileBookmark

on blur form validation

Hi i have a onblur within a input textbox, when the user presses enter i need to validate what has been entered in to the textbox.

i have tried the code below, the alert pops up fine but then my form still submits, how can i stop the form submitting?

[code]
<script language=”javascript”>
<!–
function checkQty(thisform, entry)
{
if (thisform.value < 1)
{
thisform.value = “0”
alert (“This is a Javascript Alert”)
return false

}
if (thisform.value > entry)
{
alert (“This is a Javascript Alert”)
return false

}
}

–>
</script>

<input type=”text” name=”QtyTextBox<%=i%>” size=”3″ onblur=”checkQty(this, <%=strLeft%>)” maxlength=”5″ value=”0″/>
[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Totte_chDec 18.2007 — Try this:
[CODE]<form onSubmit="return checkQty(document.forms['your_form'].elements['QtyTextBox'], 5);">
<input type=text name="QtyTextBox" size=3 maxlength=5 value="0">
</form>[/CODE]

I think this would like to work fine...
Copy linkTweet thisAlerts:
@macca242424authorDec 18.2007 — Hi Thanks for that,

but i need to have the onblur on the textbox or

what i need is

when a user enters a value

the use can either hot the tab key or the enter key and then checks the value and submits the form if the value is correct
Copy linkTweet thisAlerts:
@Totte_chDec 18.2007 — Try to add this to the input-element:
[CODE]<form onSubmit="return checkQty(document.forms['your_form'].elements['QtyTextBox'], 5);" name="your_form">
<input type=text name="QtyTextBox" size=3 maxlength=5 value="0" [B]onBlur="document.forms['your_form'].submit();"[/B]>
</form>[/CODE]
×

Success!

Help @macca242424 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.24,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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