Conditional loading of a Dialog

This section is for posting questions which are not directly related to WYSIWYG Web Builder.
Examples of off topics: web server configuration, hosting, programming related questions, third party scripts.

Note that these questions will generally not be answered by the administrators of this forum.
Post Reply
User avatar
alex4orly
 
 
Posts: 632
Joined: Mon Jan 20, 2014 8:17 am
Location: Australia
Contact:

Conditional loading of a Dialog

Post by alex4orly »

I added a Modal dialog onto a page, I have the "Show dialogue Automatically" Unchecked
I want to show / load it to the visitor only based on a Condition (if a == '2') for example inside a Javascript function

I DO NOT want it trigerred by a button click...

Any suggestions?

Thanks
User avatar
Pablo
 
Posts: 21702
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Conditional loading of a Dialog

Post by Pablo »

User avatar
alex4orly
 
 
Posts: 632
Joined: Mon Jan 20, 2014 8:17 am
Location: Australia
Contact:

Re: Conditional loading of a Dialog

Post by alex4orly »

I must be a real dummy.... I also never used JQuery....
Can't figure it out, so here is my conditional statement :

if (a == '2')
{
The Dialogue ID = entervilla;
it is unchecked to load automaticaly
and I want to make it come up if the condition is met
}

Thanks again
User avatar
Pablo
 
Posts: 21702
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Conditional loading of a Dialog

Post by Pablo »

Something like this:

Code: Select all

$("#entervilla").dialog("open");
User avatar
alex4orly
 
 
Posts: 632
Joined: Mon Jan 20, 2014 8:17 am
Location: Australia
Contact:

Re: Conditional loading of a Dialog

Post by alex4orly »

Yes, this does the trick - although I do noty understand how it works....
Anyway - I want to replace this code:

user = prompt("Please enter your Villa Number");

With this : $("#entervilla").dialog("open");

The "Prompt" function is not ver elegant, nor easy to notice poping up at the top of the screen
But I have no idea on how to grab the return value from the dialog, and hold the continuation of the scrip from executing while the visitor is entering their villa number

Thanks again
User avatar
Pablo
 
Posts: 21702
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Conditional loading of a Dialog

Post by Pablo »

You can add input controls (editbox, textarea, button) on the dialog and then use JavaScript do to get the values.
User avatar
alex4orly
 
 
Posts: 632
Joined: Mon Jan 20, 2014 8:17 am
Location: Australia
Contact:

Re: Conditional loading of a Dialog

Post by alex4orly »

Yes, I did just that - below is my code, I welcome any comments

<script type="text/javascript">

var villafrominput = 0;
var flag = true;
var user = "";

// This gets executed only if no cookie was found
function getvilla() /// ON the OK click
{
// Get the user input from the dialog
user = document.getElementById("Editbox1").value;
flag = false;

if (user!= "" && user!= null)
{
createCookie("beleura5", user, num);
window.location.href = "http://www.beleuramyhome.org.au/writelog.php?myvilla=" + user;
}
else // Go to the error page
{
window.location.href = "http://www.beleuramyhome.org.au/loginfail.php"
}
}

function createCookie(cookieName,cookieValue,daysToExpire)
{
var date = new Date();
date.setTime(date.getTime()+(daysToExpire*24*60*60*1000));
document.cookie = cookieName + "=" + cookieValue + "; expires=" + date.toGMTString();
}

function accessCookie(cookieName)
{
var name = cookieName + "=";
var allCookieArray = document.cookie.split(';');
for(var i=0; i<allCookieArray.length; i++)
{
var temp = allCookieArray.trim();

if (temp.indexOf(name)==0)
{
return temp.substring(name.length,temp.length);
}
}
return "";
}

function checkCookie()
{
user = accessCookie("beleura5");

// This is first time visitor, cookie is not yet there
if (user == "")
{
// Bring up the dialog for user to enter the villa number (Thanks Pablo)
$("#entervilla").dialog("open");

num = 365;// Set up cookie expiry for one year

if(flag) // Make the screen hold on, until visitor clicks OK
{
setTimeout(foo, 100);
}
}
// pass the user / villa number into the php for processing
window.location.href = "http://www.beleuramyhome.org.au/writelog.php?myvilla=" + user;
}
</script>
User avatar
Pablo
 
Posts: 21702
Joined: Sun Mar 28, 2004 12:00 pm
Location: Europe
Contact:

Re: Conditional loading of a Dialog

Post by Pablo »

I'm sorry, I cannot help with custom code.
I was just trying to point you in the right direction.
User avatar
alex4orly
 
 
Posts: 632
Joined: Mon Jan 20, 2014 8:17 am
Location: Australia
Contact:

Re: Conditional loading of a Dialog

Post by alex4orly »

That's OK, it works fine for me

Thanks again
Post Reply