<a href="javascript: var ret = confirm('Are you sure you want to logout');">Logout</a>
I assume you specify href as a normal link - and possibly change the href after onload()?
Could you use the <a> onclick handler to perform the confirm and upon return would the link carry out as normally - assuming you don't cancel the event?
I'll check the last statement out, but i'm curious how you all make accessible links like above?
Anyway... I use jquery (thanks Kieran!) to replace the standard links after document has loaded. You could do this w/out jquery, but it's much easier with it.
The Ninja Space Goat wrote:Client side would be more appropriate.
Anyway... I use jquery (thanks Kieran!) to replace the standard links after document has loaded. You could do this w/out jquery, but it's much easier with it.
The dollar sign is actually a function name believe it or not. Jquery is hands down the coolest js library I've every seen. Basically what that little snippit does is find all elements that could be matched with ".delete" (think css selectors), then it changes the attib(ute) href to javascript:; then it adds a function to the onclick event.
<a href="/logout.php" title="log out of the system" class="confirm">Logout</a>
<script type="text/javascript">
$(function(){
$('.confirm').click(function(){
var act = $(this).attr('title')?$(this).attr('title'):'do this';
return confirm('are you sure you want to '+act+'?');
});
});
</script>
<script type="text/javascript">
$(function(){
$("input[@pattern]").keyup(function(){
if(eval('/'+$(this).attr('pattern')+'/i').test(this.value)){
$(this).css('color','green'); // is valid
// maybe enable the form here
}else{
$(this).css('color','red'); // is invalid
// maybe disable the form here
}
});
});
</script>
<input type="text" name="email" pattern="^[\d\w\.-_]+@([\d\w][\d\w\.-|]+[\d\w]\.)+\w{2,4}$"/>
The syntax will be valid and working when xforms are supported, and then we would just not use jQuery for this.
You could just add a "check all" function to the form submit button to validate before submission.