/    Sign up×
Community /Pin to ProfileBookmark

Onclick triggered after onblur on Mac browsers

Hi,

We have a couple of textboxes in a form. All of which are validated onblur. The form is submitted onclick of an anchor tag.
Submit

Windows platform browsers(Firefox, Safari, Chrome, IE): When validateMyText() returns false, onclick is not triggered. This is the expected and existing behaviour.

Mac platform browsers (Firefox, Safari): Even after validateMyText() returns false, onclick event is triggered, which submits the form.

Background: This is a legacy application that was supported only on Windows platform and IE browser. Now it has to be enhanced to work on all the browsers(Firefox, Safari, Chrome, IE) on Windows and Firefox, Safari on Mac.

Thanks,
Mathew

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorJul 13.2010 — The form is submitted onclick of an anchor tag.[/QUOTE]
How? can we see the HTML code of that anchor and the handler?
Copy linkTweet thisAlerts:
@mathew_vinayauthorJul 14.2010 — I am sorry the html tags got filtered out when I posted. The following is the html and handler.

<script>

function validateMyText(){

// do field validation

// if success

return true;

// else {

alert("Please check the text box value");

return false;

}

}

</script>

<form name="myform" action="mytestpage.jsp">

<input type="text" name="myText" id="myText" onblur="return validateMyText()"/>

<a href="#" onclick="mytestpage.jsp">Submit</a>

</form>
Copy linkTweet thisAlerts:
@KorJul 14.2010 — And where the submit in this code? I see neither a classical submit, nor a javascript one?

Look: the standard way to validate a form is to allow/block the [B]submit[/B] action of a FORM element, not the [B]click[/B] action of a link or an element. Schema goes like that:
<i>
</i>&lt;script type="text/javascript"&gt;
function validate(){
if([I]condition is not passed[/I]){
return false;
}
}
&lt;/script&gt;

<i>
</i>&lt;form action="mytestpage.jsp" onsubmit="return validate()"&gt;
...
&lt;/form&gt;

You see now that return false should act upon the [I]onsubmit[/I] event.
×

Success!

Help @mathew_vinay 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.17,
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,
)...