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
Conditional loading of a Dialog
Re: Conditional loading of a Dialog
Maybe this will be helpful?
https://api.jqueryui.com/dialog/#method-open
https://api.jqueryui.com/dialog/#method-open
Re: Conditional loading of a Dialog
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
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
Something like this:
Code: Select all
$("#entervilla").dialog("open");
Re: Conditional loading of a Dialog
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
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
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
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>
<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
I'm sorry, I cannot help with custom code.
I was just trying to point you in the right direction.
I was just trying to point you in the right direction.
Re: Conditional loading of a Dialog
That's OK, it works fine for me
Thanks again
Thanks again