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: 821
Joined: Mon Jan 20, 2014 8:17 am
Location: Australia
Contact:

Conditional loading of a Dialog

Post by alex4orly » Wed Aug 28, 2019 11:59 pm

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: 18586
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Conditional loading of a Dialog

Post by Pablo » Thu Aug 29, 2019 6:27 am


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

Re: Conditional loading of a Dialog

Post by alex4orly » Thu Aug 29, 2019 8:35 am

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: 18586
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Conditional loading of a Dialog

Post by Pablo » Thu Aug 29, 2019 9:04 am

Something like this:

Code: Select all

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

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

Re: Conditional loading of a Dialog

Post by alex4orly » Thu Aug 29, 2019 10:31 pm

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: 18586
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Conditional loading of a Dialog

Post by Pablo » Fri Aug 30, 2019 5:47 am

You can add input controls (editbox, textarea, button) on the dialog and then use JavaScript do to get the values.

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

Re: Conditional loading of a Dialog

Post by alex4orly » Fri Aug 30, 2019 8:27 am

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: 18586
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Conditional loading of a Dialog

Post by Pablo » Fri Aug 30, 2019 8:57 am

I'm sorry, I cannot help with custom code.
I was just trying to point you in the right direction.

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

Re: Conditional loading of a Dialog

Post by alex4orly » Fri Aug 30, 2019 9:19 am

That's OK, it works fine for me

Thanks again

Post Reply