6 Replies - 1832 Views - Last Post: 27 July 2013 - 02:38 PM

#1 efraingb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-July 13

My function don't work without an event if I call it

Posted 24 July 2013 - 04:57 PM

I developed a function to have a beautiful alert in my Web site. For that I use sexy.alert inside my function. If I call my function using a event (for example click) it do the things I want it do, but if I don't use an event (and that's really necessary) it don't work as I need, only with a event. Why? Is a characteristic of sexy.alert?
This is my code (also attached you can find the files, based in the files I downloaded. The file I showed you is prueba_alert enviado.html):

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery.easing.1.3.js"></script>
<script type="text/javascript" src="sexyalertbox.v1.2.jquery.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="sexyalertbox.css"/>
<script type="text/javascript">
function betteralert(text, title_outside) //title_outside is an optional parameter
{
text_print="";

if (title_outside == undefined) //If there isn't the title in the parameters, so it uses the default title.
{
var title="Thanks for use Wagerplus.com";
}
else
{
var title=title_outside;
}
text_print="<h1>"+title+"</h1><em></em><br/><p> &nbsp;&nbsp;"+text+"</p>'"; //The text will be in the alert
try
{
if(!Sexy.alert(text_print))//print 
{
return false;
}
else
{
alert(text);
return true;
}
}
catch(change_type_alert)
{
alert(text+" Entro al catch");
}
title_outside=undefined;
}
</script>
<title>Prueba - Alerta que se desliza</title>
</head>
<body>
<p>
</br><!-------------------------------------------->
<a href="#" onclick="betteralert('This is the text','This is the title');"> <!----------call to the function-------------->
Show alert<!-------------------------------------------->
</a>

</p>
<!--
------------------------------------------------------------------->
<!----------------------------------------------------------------->
<!-------I need the function work as you can see below,------------>
<!-------I have some functions working as I need work betteralert.->
<!-------It work well if I use jalert and not sexy.alert.---------->
<!-------but I need sexy.alert or something like that, I mean,----->
<!-------something really beautiful--------------------------------->
<!----------------------------------------------------------------->
<script type="text/javascript">
betteralert("Thanks for use our website <p>&nbsp;&nbsp;This is the function betteralert</p>");
</script>
-->
</body>
</html>

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: My function don't work without an event if I call it

#2 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,921
  • Joined: 30-April 10

Re: My function don't work without an event if I call it

Posted 24 July 2013 - 05:39 PM

I don't see where you actually call Sexy.alert(message);

Also, you need to work on code indentation. Your code is hard to read.

This post has been edited by laytonsdad: 24 July 2013 - 05:40 PM
Reason for edit:: added note

Was This Post Helpful? 0
  • +
  • -

#3 efraingb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-July 13

Re: My function don't work without an event if I call it

Posted 26 July 2013 - 07:41 AM

View Postlaytonsdad, on 24 July 2013 - 05:39 PM, said:

I don't see where you actually call Sexy.alert(message);

Also, you need to work on code indentation. Your code is hard to read.


Good morning!

Thanks for your answer. And for you advice. I will work in that.

My friend, the call to sexy.alert is in the line 25. In the "if". In this line: if(!Sexy.alert(text_print)).
I think that's well because my function work if I call it with an event. The problem is if I don't use an event. So my theory is that sexy.alert never work if I don't use an event for call it. I want to know if somebody knows if sexy.alert have this or other problem like that. And some advice for correct it. Or if somebody knows what can be the problem with sexy.alert, because if I use other functions for alerts so my function work well. But I need: or sexy.alert or something like that, I mean, something beautiful.

I will be gratefull for any comment.
Was This Post Helpful? 0
  • +
  • -

#4 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,921
  • Joined: 30-April 10

Re: My function don't work without an event if I call it

Posted 26 July 2013 - 12:34 PM

Sorry about that I must have skimmed to fast.

After having a try at this again I believe that you will have to use an event to trigger the function.

When do you want to have the alert show?
Was This Post Helpful? 0
  • +
  • -

#5 efraingb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-July 13

Re: My function don't work without an event if I call it

Posted 26 July 2013 - 02:07 PM

View Postlaytonsdad, on 26 July 2013 - 12:34 PM, said:

Sorry about that I must have skimmed to fast.

After having a try at this again I believe that you will have to use an event to trigger the function.

When do you want to have the alert show?


I was wrong. I understood that when I read your answer. I will explain that. I had used jAlert. Always to do something after a click. But sometimes, I need an alert after an onload event. But with jalert and onload I didn't have to write a line of code that say "onload". In the Website I only call my function in the body. My mistake was I assumed with sexy.alert I dont have to write the words "onload" like a did with jAlert. And yes, of course onload is an event, I dont know why I forgot that.
In summary:
I write: betteralert("Title <p>&nbsp;&nbsp;Text</p>");
And I had to use:
<body onload="betteralert("Title <p>&nbsp;&nbspText</p>");">
Thanks for your help. I hope my mistake can help somebody in the future.

This post has been edited by laytonsdad: 26 July 2013 - 05:47 PM
Reason for edit:: added inline code tags

Was This Post Helpful? 0
  • +
  • -

#6 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,921
  • Joined: 30-April 10

Re: My function don't work without an event if I call it

Posted 26 July 2013 - 05:46 PM

I am glad I could help.

You can also create event listeners like this:

document.addEventListener(EVENT, FUNCTION);


This post has been edited by laytonsdad: 26 July 2013 - 05:51 PM
Reason for edit:: Added example

Was This Post Helpful? 0
  • +
  • -

#7 efraingb  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 24-July 13

Re: My function don't work without an event if I call it

Posted 27 July 2013 - 02:38 PM

View Postlaytonsdad, on 26 July 2013 - 05:46 PM, said:

I am glad I could help.

You can also create event listeners like this:

document.addEventListener(EVENT, FUNCTION);



Thank you very much!!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1