both alert() and confirm() windows on screen

J

jivanmukta

Hello,
I have such problem that on my page two windows (alert and confirm)
appear together. Here is the code:

<head>
<script type="text/javascript">
function check(elem) { if (elem.value b³êdna) alert('Invalid
value.'); }
</script>
</head>
<body>
<form ...>
<input type="text" onblur="check(this);">
<input type="button" onclick="if (confirm('Are you
sure?')) ...submit
();">
</form>
</body>

First window is alert (called onblur) and the second one is confirm
(called
onclick). I want to achieve validation onblur (field-after-field
validation) and validation onclick (summary-like validation). I don't
know how to write it correctly.
Please help. Thanks in advance.
 
T

Thomas 'PointedEars' Lahn

I have such problem that on my page two windows (alert and confirm)
appear together. Here is the code:

<head>
<script type="text/javascript">

Do not forget to include before this tag:

- the document title (<http://www.w3.org/QA/Tips/good-titles>)
- the declaration of the document encoding (only needed for validation of
local files; check your HTTP Content-Type header first)
- the declaration of the default scripting language (for event-handler
attributes)
- other items required by the HTML 4.01 Specification
(<http://www.w3.org/TR/html4/>)

See also said:
function check(elem) { if (elem.value błędna) alert('Invalid
value.'); }

Should be window.alert(...), and something is wrong with your `if' statement
as well.
</script>
</head>
<body>
<form ...>
<input type="text" onblur="check(this);">

You might want to lose type="text" because that's the default and no known
common UA needs it.
<input type="button" onclick="if (confirm('Are you
sure?')) ...submit
();">
</form>
</body>

First window is alert (called onblur) and the second one is confirm
(called
onclick). I want to achieve validation onblur (field-after-field
validation) and validation onclick (summary-like validation). I don't
know how to write it correctly.

You don't want to annoy your users with *this* `onblur' value anyway.

Anyhow: Avoid simple buttons in forms; those make your form inaccessible for
users without available script support. (If you use them, generate them
with scripting.) Use a submit button and the `submit' event of the form
instead:

<head>
...
<script type="text/javascript">
function checkForm(f)
{
if (errorCondition)
{
/* ... */
return false;
}

return window.confirm('Are you sure?');
}
</script>
</head>

<body>
...
<form ... onsubmit="return checkForm(this)">
<input ...>

<input type="submit" value="...">
<!-- or the following -->
<input type="image" src="..." alt="...">
<!-- or one of the following, but only if you need more than
text or a single image as caption; watch for compatibility! -->
<button type="submit">...</button>
<button type="image">...</button>
</form>
Please help. Thanks in advance.

HTH. You are welcome.

It would be appreciated if you posted using your real name next time.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
<!-- or one of the following, but only if you need more than
text or a single image as caption; watch for compatibility! -->
<button type="submit">...</button>
<button type="image">...</button>

Ignore the latter, the Valid values for the `type' attribute of the `submit'
element are `button', `submit', and `reset'. If you want a graphical submit
button with the `button' element, use <button ...>...<img ...>...</button>.
(Obviously, you only need the `button' element if you want more than just
either text or image.)

<http://www.w3.org/TR/html401/interact/forms.html#h-17.5>


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
Thomas said:
<!-- or one of the following, but only if you need more than
text or a single image as caption; watch for compatibility! -->
<button type="submit">...</button>
<button type="image">...</button>

Ignore the latter, the Valid values for the `type' attribute of the `submit'
element are `button', `submit', and `reset'. [...]

Of the _button_ element. (Wasn't my day, apparently.)


PointedEars
 

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,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top