Page 1 of 1

Conditional loading of a Dialog

Posted: Wed Aug 28, 2019 11:59 pm
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

Re: Conditional loading of a Dialog

Posted: Thu Aug 29, 2019 6:27 am
by Pablo

Re: Conditional loading of a Dialog

Posted: Thu Aug 29, 2019 8:35 am
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

Re: Conditional loading of a Dialog

Posted: Thu Aug 29, 2019 9:04 am
by Pablo
Something like this:

Code: Select all

$("#entervilla").dialog("open");

Re: Conditional loading of a Dialog

Posted: Thu Aug 29, 2019 10:31 pm
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

Re: Conditional loading of a Dialog

Posted: Fri Aug 30, 2019 5:47 am
by Pablo
You can add input controls (editbox, textarea, button) on the dialog and then use JavaScript do to get the values.

Re: Conditional loading of a Dialog

Posted: Fri Aug 30, 2019 8:27 am
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>

Re: Conditional loading of a Dialog

Posted: Fri Aug 30, 2019 8:57 am
by Pablo
I'm sorry, I cannot help with custom code.
I was just trying to point you in the right direction.

Re: Conditional loading of a Dialog

Posted: Fri Aug 30, 2019 9:19 am
by alex4orly
That's OK, it works fine for me

Thanks again