How to prevent Mozilla using a link if a wrong number is in an input box

S

Stefan Mueller

In my example the focus should only jump to textbox2 if you press the tab
key and if '11' is in textbox1. That works fine.
However if you enter e.g. '12' in textbox1 and click on 'Link', Mozilla
shows the alert 'Wrong numer' but also jumps to 'www.google.com'.
Opera and IE don't do that what's in my opinion the correct behavior.

<html>
<body>
<script type = 'text/javascript'>

function test(object) {
if (object.value == 11) {
return (true);
}
else {
alert("Wrong number");
return (false);
}
}

</script>
<form name = "my_form" action = "" method = "post" accept-charset =
"iso-8859-1">
<table id = "my_table" border = "1">
<tr>
<td>
<input type = "text" name = "my_textbox1" onBlur = 'if
(!test(document.my_form.my_textbox1))
{setTimeout("document.my_form.my_textbox1.focus();", 1);}'>
<input type = "text" name = "my_textbox2">
<a href="http://www.google.com">Link</a>
</td>
</tr>
</table>
</form>
</body>
</html>

How can I prevent Mozilla from jumping to 'www.google.com' if the value in
the input box is wrong?
Stefan
 
L

Lee

Stefan Mueller said:
In my example the focus should only jump to textbox2 if you press the tab
key and if '11' is in textbox1. That works fine.
However if you enter e.g. '12' in textbox1 and click on 'Link', Mozilla
shows the alert 'Wrong numer' but also jumps to 'www.google.com'.
Opera and IE don't do that what's in my opinion the correct behavior.

I don't see it jumping to Google. I just see the sort of very
annoying behavior you expect when using onblur.

When I change onBlur to onchange, it works for me as you seem
to want. It still doesn't make sense to me to ask for a value
when you'll only accept one answer. If this is supposed to be
some sort of password, consider that anybody can view the source
and see what number you require.
 
S

Stefan Mueller

I've a huge table with many input fields. For each input field I'd like to
program a Javascript function which checks if the input is correct (e.g.
date in the right format / only numbers / number not below zero / ...) if
the focus leaves the input field. Today I do this with onBlur and it works
quite well.
If you click on the header of the table (href) the corresponding column gets
sorted. If you've entered a wrong input and you click on the header of the
table, the table gets not sorted but you see the alert message 'Wrong numer'
according to my example.
However, this works only with Internet Explorer and Opera. With Mozilla
Firefox you get the alert message 'Wrong numer' but the table also gets
sorted and the input field with the wrong input lost its focus.

Is there any way to prevent Mozilla from executing the href (sort of the
table / in my example jump to www.google.com) if the input of the input
field is not correct?
Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top