Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2008, 03:30 PM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default Creating a Javascript Alert

Chaps,

What i am trying to achieve is the ability to produce a CSS styled alert with a close button.

After many varied examples i have cobbled an initially well written piece of JavaScript into my draconian version of script hence my post.!

The validation method i am using is classic asp and some SQL queries.. Sorry!

The initiation of the alert would be from a query string and associated error type.

Code:
<%qs=request.QueryString("qs")%>


The Style Sheet attributes are:

HTML Code:
<style type="text/css">
/** Quick basic stylising */
body, div, td, th {
 font-family: Tahoma;
 size: 11px;
}
h1, h2, h3 {
 font-weight: 100;
 font-family: Tahoma;
}
/** Hidden State for the dialog */
div.hiddenState {
 visibility: hidden;
 display: none;
}
/* Some rought layout, could be anything including backgrounds etc */
div.visibleNotifyMsg {
 position: absolute;
 top: 150px;
 left: 150px;
 width: 300px;
 background: #6382d2 url("/images/icons/info-i-icon.png");
  background-repeat:no-repeat;
 color: #FFF;
 border: 1px solid #3a5daf;
  border-right-width: 2px;
  border-bottom-width: 2px;
 padding-left:25px;
  padding-right:3px;
  padding-bottom:10px;
  padding-top:3px;
}
</style>


The JavaScript Used so far

Code:
<script type="text/JavaScript" language="JavaScript">

function notifyErrors(id, errors, visibleStateCSS) {
 // Locate and update our popup window
 object = document.getElementById(id);
 object.innerHTML = '<strong>The following errors occured when validating your form:</strong><pre>';
 object.innerHTML += '<strong>The following errors occured when validating your form:</strong><pre>';
 object.innerHTML += '</pre><p><input type="image" src="/images/buttons/b-close.png" onclick="javascript:document.getElementById(\'' + id + '\').className = \'hiddenState\';" value="Close Window" /></p>';
 object.className = visibleStateCSS; 
}

function validate() { 
 errStack = new Array();
 // Check the email address, if error, push into stack
 notifyErrors('notifyPopup', errStack, 'visibleNotifyMsg');
 
}
</script>


Below example of simple form

HTML Code:
<form name="form" methos="post" action="test.asp">
<input type="button" value="Submit" /><div id="notifyPopup" class="hiddenState"></div>
</form>


Using asp i have the following trigger to initiate the javascript separatley from the form

Code:
<% If qs = "er" then%>
<script>
validate();
</script>
<%End If%>


I fully admit my knowledge of JavaScript is at best a Neolithic grasp but the upshot of my issue is the close button on the created alert is associated with the form.

As a result when you select the "close" button on the alert it initiates the form and tries to open for example test.asp.

My finger in the air assumption is that

Code:
object = document.getElementById(id);


is the association.

Is there a way of either simplifying the JavaScript to correctly close the alert or more likely a simpler way.

Any input appreciated
 
Old December 16th, 2008, 04:40 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

I think you will find that if you change this line:

javascript Code:
object.innerHTML += '</pre><p><input type="image" src="/images/buttons/b-close.png" onclick="javascript:document.getElementById(\'' + id + '\').className = \'hiddenState\';" value="Close Window" /></p>';

to something like
javascript Code:
object.innerHTML += '</pre><p><input type="image" src="/images/buttons/b-close.png" onclick="javascript:document.getElementById(\'' + id + '\').className = \'hiddenState\'; return false;" value="Close Window" /></p>';

or

javascript Code:
object.innerHTML += '</pre><p><a onclick="javascript:document.getElementById(\'' + id + '\').className = \'hiddenState\'; return false;" style="cursor:pointer;"><img src="/images/buttons/b-close.png" /></a></p>';

it will correct your problem.

The reason that your form is posting is because you are using an INPUT tag for your image and, the default behavior of is to post the form. To prevent this from happening you simply use 'return false;' in your onclick event to prevent the post.

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old December 16th, 2008, 05:10 PM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 104
Thanks: 9
Thanked 1 Time in 1 Post
Default

Thanks dparsons,

That works perfectly.
 
Old December 16th, 2008, 05:15 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No problem, glad it worked out for you! ^^
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
 
Old February 18th, 2009, 09:21 PM
Authorized User
 
Join Date: Dec 2008
Posts: 50
Thanks: 1
Thanked 5 Times in 5 Posts
Default

Check this website out, a bit doughy but interesting. check the top notification.

http://www.ready4recession.com/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a alert application aadz5 JSP Basics 0 August 5th, 2006 10:08 AM
Javascript alert error Ed7777 Javascript How-To 5 June 25th, 2004 02:23 PM
Javascript alert box Adam H-W Javascript How-To 13 March 4th, 2004 05:11 AM
Javascript "alert()" acts modeless cppman Javascript 2 September 16th, 2003 09:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.