Custom Alert Box

May 9, 2007

I've tested it in most recent versions of IE, FF, Opera, and Safari.

The first parameter is the alert's text, if a second parameter is passed, it is the alert's title, else it will just have "Alert" in the title.

You can fire the function as many times as you like, any alert's thrown after the first will set themselves on top of each other slightly staggered much like the built in alert.

The alert will automatically be placed in a visible place regardless of where the page has scrolled. They will also stay in that same place in relation to the screen if the user scrolls after the alert has fired.

The top most alert is the only one clickable and moveable until it has been acknowledged (Much like a regular alert).

The benefit of this is that it does not freeze the user's interface once the alert is thrown.

Here's the code:

Javascript:

//*****************************
// Custom Alert Box
// Free to use with credits in tact.
// Written By Adam Matthews aka Basscyst
//AdamDMatthews@Gmail.com
//*****************************
function msgBox(msg,hdr){
if(!document.getElementById('alerts')){
var div=document.createElement('div');
div.setAttribute('id','alerts');
document.body.appendChild(div);
}
var div=document.createElement('div');
div.className="alertbox";
var h3=document.createElement('h3');
h3.className="alerttitle";
var p=document.createElement('p');
p.className="alerttxt";
var footdiv=document.createElement('p');
footdiv.className="alertfoot";
div.appendChild(h3);
div.appendChild(p);
div.appendChild(footdiv);
var but=document.createElement('input');
but.setAttribute('type','button');
but.className='alertbut'
but.setAttribute('value','OK');
footdiv.appendChild(but);
var hdr=(hdr) ? hdr : "Alert!";
h3.appendChild(document.createTextNode(hdr));
var cut=msg.split("
");
var len=cut.length;
p.appendChild(document.createTextNode(cut[0]));
for(var i=1;i<len;i++){
p.appendChild(document.createElement('br'));
p.appendChild(document.createTextNode(cut[i]));
}
document.getElementById('alerts').appendChild(div);
window.onscroll=function(){
placeAlerts();
}
window.onresize=function(){
placeAlerts();
}
placeAlerts();
}
var posX;
var posY;
function mouseXY(e){
if (!e){
var e = window.event;
}
if (e.clientX)
{
posX = e.clientX + document.documentElement.scrollLeft;
posY = e.clientY + document.documentElement.scrollTop;
}
else
{
posX = Math.max(e.pageX,0);
posY = Math.max(e.pageY,0);
}
var coord=new Array();
return coord;
}
if(document.captureEvents){
document.captureEvents(Event.MOUSEMOVE)
}
function placeAlerts(){
var alerts=document.getElementById('alerts').getElementsByTagName('div');
var len=alerts.length;
var x=0;
var y=300;
var w=document.body.clientWidth;
var h=document.body.clientHeight;
for(var i=0;i<len;i++){
alerts[i].style.zIndex=i+100;
alerts[i].getElementsByTagName('h3')[0].onmousedown="";
alerts[i].getElementsByTagName('input')[0].onclick="";

if(window.pageYOffset){
alerts[i].style.top=y+(window.pageYOffset)+'px'
}else{
alerts[i].style.top=y+(document.documentElement.scrollTop)+'px'
}
alerts[i].style.left=(w / 2)- (343 / 2) + x +'px';
x=x+15;
y=y+15;
if(i==len-1){
var h3=alerts[i].getElementsByTagName('h3')[0];
var but=alerts[i].getElementsByTagName('input')[0];
but.onclick=function(){
this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);
var alerts=document.getElementById('alerts').getElementsByTagName('div');
if(alerts.length==0){
window.onscroll="";
}
placeAlerts();
}
h3.onmousedown=function(event){
this.parentNode.setAttribute('id','active_alert');
var event=(event)?event:arguments[0];
mouseXY(event);
start_x=posX;
start_left=document.getElementById('active_alert').style.left.replace('px','');
adjust=posX-start_left;
document.onmousemove=function(event){
var event=(event)?event:arguments[0];
mouseXY(event);
var obj=document.getElementById('active_alert');
obj.style.left=posX-adjust+'px'
obj.style.top=posY-5+'px'
};
}
h3.onmouseup=function(){
document.onmousemove="";
this.parentNode.setAttribute('id','');
}
}
}
}

Function Call

msgBox("You have done something real bad!
So Bad, oh so bad!","Ya shoudn't of done it boy!")


CSS

.alertbox{
width:344px;
position:absolute;
padding:0px;
margin:0px;
border:solid 1px #FFFFFF;
}
.alerttitle{
background-color:#9B1317;
color:#FFFFFF;
font-size:12px;
width:344px;
cursor:pointer;
text-align:center;
margin:0px;
padding:0px;
}
.alerttxt{
background-color:#E7EFF7;
margin:0px;
font-size:11px;
text-align:center;
padding:0px;
width:344px;
}
.alertfoot{
background-color:#9B1317;
text-align:center;
width:344px;
margin:0px;
padding:0px;
}
.alertbut{
margin-top:2px;
cursor:pointer;
}

View 3 Replies


ADVERTISEMENT

Custom Made Alternative To "alert()"

Nov 27, 2007

I was wandering how would I make my own version of "alert()", or prompt(). I see jquery (i think) has something like this. But I'd like to make it myself, for the perpuse of getting experince. So, first problem is, I'm not sure how would I temporary "lock background", so that when your own alert shows, you must select ok. Is there maybe any function in JS that allows this (to lock temporary website expect certain elements (which would be div in this example, that would contain my alert box) or in other words, make site unavailable to you until you press OK button on your custom made alert (div element or something) message)?

View 5 Replies View Related

Alert If Button Pressed - It Should Give An Alert That The Alert Is Not Checked?

Oct 21, 2011

heres my code:

Code:
<script language="JavaScript">
var checkobj
function agreesubmit(el){[code]....

i need to make it like if the button is clicked and there the agreement checkbox is not checked.. it should give an alert that the alert is not checked.. i know that would require a if and else statement but i cant figure out how to do it

View 3 Replies View Related

JQuery :: JConfirm Alert / After Receiving Confirm Alert / Fires Event Of OK Button

Nov 13, 2010

i am facing a problem after using jquery jconfirm alert. Issue is that after receiving confirm alert, when user press tab to go on Cancel button and press Enter key there, despite of firing event of Cancel button, it fires the event of OK button. this issue is not produced when user press the cancel button by mouse. Waiting for your replies.

View 1 Replies View Related

JQuery :: Throw An Alert With The Attributes Of A Submit Button In The Alert

Feb 16, 2011

I am trying to throw an alert with the attributes of a submit button in the alert.

What am I doing wrong?

View 4 Replies View Related

JQuery :: Receiving And Alert With [object Object] When It Should Be Alert The JSON Data

Jun 10, 2010

jquery code:

$.ajax({
url: "validate_livestock_form/index/",
type: 'POST',
dataType: "json",
data: form_data,
success: function(data) {
alert(data);
[Code]...

php page is echoing out:{"species":"Please select a species!"} I double checked the response from the php and firebug shows the same. On success alert is not alerting the JSON data instead, I'm receiving [object Object]. Why is that and how do what should I do to fix this?

View 3 Replies View Related

Ajax :: Alert(textarea2); Shows Nothing But If I Place Another Alert(textarea2) Right After The First One It Works?

Jul 10, 2009

I'm currently working on MySQL/PHP/JavaScript project using AJAX. I came across some weird abnormality .for some reason alert(textarea2); shows nothing but if I place another alert(textarea2); right after the first one it works, second pop-up contains responseText....also I've tried alert(resp.responseText); it worked fine,

new Ajax.Request("categories-inset.php",
{
method: 'get', [code]....

View 9 Replies View Related

Custom Function

Mar 25, 2006

I have created a function.

function unHide (fieldname)
{
.... not important...
document.form1.fieldname.style.visibility = 'visible'

}

I have a field name called country in a form.
When the onclick="unHide('country')" is used then the above function
does not work
but if i change the following line within the function
document.form1.country.style.visibility = 'visible' then it works.

What am i doing wrong.

View 5 Replies View Related

Resolved Custom Pop Up Box

Aug 8, 2010

I am looking for a custom pop up box, but there is only 3 kinds (Alert, Confirm, Prompt). Neither of those will work.

View 13 Replies View Related

How Can We Get ChildNodes From A Custom Tag?

Dec 26, 2003

i wrote a very simple HTML page to test some DOM features between Mozilla and IE. Mozilla is perfect everything went fine and i got the childNodes from my custom tag ( this tag i named <blah> ), inside this tag there is two <span>, that i retrieved. But with IE i really could figure out how its done! Code:

View 1 Replies View Related

Setting Custom Properties

Jul 23, 2005

I know that I can read/write custom properties of an object by using
the following:

Setting:
document.all['Control'].customProp = "this";
Getting:
document.all['Control'].customProp;

Is there a way I can run code when this custom property is set. Or
perhaps there is a way to create a custom method?

Example:
<span id="MySpan"><input type="text"></span>

I'd the property:
document.all['MySpan'].enabled = true;
To automatically do this:
document.all['MySpan'].controls[0].disabled = !thevalue;

OR the method
document.all['MySpan'].enable();
To do this:
document.all['MySpan'].disabled = false;

View 5 Replies View Related

Custom Properties On DOM Nodes

Jul 23, 2005

I try to associate DOM nodes with other objects. Assigning custom
properties to DOM nodes works in Firefox and Safari. It also works with
HTML nodes in IE6. However, it appears not to work with XML nodes that
are part of trees returned by XMLHttpRequest. How can I work around this
limitation? For XML nodes, I need to be able to associate at most one
object with each node.

The syntax I am using is
node.customproperty = value

View 2 Replies View Related

AppendChild Custom HTML Tag For IE

Nov 23, 2005

I have a custom HTML tag: <custom>text is here</custom>

I can do anything I would like in terms of calling methods with mozilla
but not IE 6. For instance calling appendChild in IE results in an
error. The innerHTML property is blank even though there is text
between the tag.

Is there a work around for IE. What gives with IE and being able to
access and manipulate custom tags??

View 1 Replies View Related

Custom Tags And Elements

Dec 5, 2006

I would like to include extra "hidden" information in a generated HTML page
that can be used by javascript functions.

I realise that most browsers seem to ignore any tags and attributes they
don't understand, but from what I can tell the standards do not allow me to
make up my own tags or attributes as they will fail validation.

is there any standard element name that can be used for such a purpose i.e.
passes validation but never produces any output (and ideally allows nested
elements to be rendered normally too)...

View 10 Replies View Related

Custom Hiliting Button...

Jul 20, 2005

I want to have a custom button change appearance when pressed and then
call a function and change back to its original appearance when released.

here's what i have now, which works mostly. "drop" is my handler for the
button, its argument tells me which button was pressed. i have a number
of these buttons and they are organized in a table.

there is a fair amount of superstition here, the result of many tiny
experiments i ended up with this which seems to work best: Code:

View 1 Replies View Related

Custom Tags With ExecCommand

Jul 20, 2005

Does anyone know of a way to wrap custom tags around selected text
using execCommand or otherwise?

I am developing a rich text editor for use in a web site and while
there are a few decent ones already floating around I need to
implement a few extra bits of functionality. Specifically tool tips.
Idealy I'd like to wrap custom tags around selected text using
execCommand. Ie "Selected Text" becomes:

"<a title='User inputed tooltip'>Selected Text</a>".

Any ideas?

View 1 Replies View Related

Custom Input File ?

Jul 20, 2005

I would like to use input type file, but i would like to put any file in it
when i go on the page for example when user go back after try to submit

imagine any form to fill for send information...but after the user
validate....one on the fields is bad...then the user must be correct this
field.....But i don't want another fields are empty. The user must just
correct one fields and keep another fields

View 3 Replies View Related

JQuery :: Getting Value Of Custom Attribute

Feb 19, 2010

I'm using the jquery in place editor, and I need to get the value of a custom attribute in order to send it with the form. The jquery I have is as folder... (the bit I'm having trouble with is highlighted)
$(".edit").editInPlace({
url: "./server.php",
params: "folder=" + $(this).attr('folder')
//show_buttons: true
//$('.edit').attr('folder')
});

And the html is as follows:
<span class="edit" folder="folderName">text to edit</span>
As you can see, I need to get jquery to get the attribute 'folder' value, in this case the value returned would be 'folderName'.

View 2 Replies View Related

JQuery :: Set Up A Custom Queue?

Feb 21, 2010

I was reading about delay() in the API ref and it mentioned it used the standard effects queue or a custom queue, but didn't illustrate how you set up a custom queue.

View 2 Replies View Related

Custom Alerts Not Working In IE

Aug 24, 2011

[URL]. It works awesome in all browsers but IE 7 & 8. The custom "alert" is actually a dialog box, with a background fader underneath it, kind of like lightbox. Why IE doesn't play nice?

View 3 Replies View Related

Google Map Custom Marker ?

Jan 7, 2010

I am generating a google map and plotting markers based on the IP addresses of cities stored in my database.

For each marker i display on the map I want the user to be able to see the city name and also a number that is generated from my DB.

So Id have a custom blank marker and put the city name and a number onto the marker. Is this possible?

Very similar to this: [url]

View 1 Replies View Related

Use A Custom Map With Google Maps?

Sep 26, 2011

I've seen several websites using a custom image as a map with google maps controls.I'm familiar with how to use the google maps api in general, but I don't know how to use a custom map image that isn't based on the real world, in other words it will be an image of a map from a video game, so general latitude and longitude wont apply.

View 1 Replies View Related

IFrame With Custom Scroller

Dec 27, 2003

Does anyone have a script for a scroller that scrolls a normal page in an iframe when you rollover an image (which would not be inside the iframe rather on the page the iframe is on)?

I've been searching the net for like hours and all I've found have been news tickers and marquees.

View 1 Replies View Related

Read Custom Attributes

Sep 28, 2007

Let's say i defined my own attribute, called "counter".

<div id="myid" counter="2">test</div>

I know I can read this value trough:
document.getElementById('myid').getAttribute('counter');

But is it possible to add the counter attribute to javascripts known attributes, so I could access it like:

document.getElementById('myid').counter;

View 3 Replies View Related

Custom Scroll Script

Sep 15, 2002

Well Im having some problems with a script that I got (prewritten). I altered some parts HTML wise so it works better for me, but I didnt change ANY of the JavaScript at all! But Im getting an object expected error(line 76). I dont know JavaScript at all, so if someone could kindly tell me what I need to change where so that this works. Code:

View 2 Replies View Related

Add Scrollbar In Custom Lift

Aug 25, 2010

In fact, I have a custom lift that I found on the following site: URL...What I am trying to add is to add a bar of the lift (3rd buttons).

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved