i have one php function which verify admin login like that
if($vAdmin==1)
{
$_SESSION['admin']="admin";
header("location:index.php");
}
else
{
$errMsg="Invalid Username or Password.";
}
This work perfect but i want to show the div which show the error message, so i defined the div like this and its hidden div in style.
<div class="notification">Invalid username or password. (Type anything)</div>
i have changed the above function to
if($vAdmin==1)
{
$_SESSION['admin']="admin";
header("location:index.php");
}
else
{?>
$('div.notification').fadeIn();
setTimeout(function() {
$('div.notification').fadeOut('slow');
}, 3000);
<?}
?>
my basic purpose is when its not verified just show the div and hide it.
but its not working?
Thanks
Change the else part of your code to the following:
else
{
echo <<<EOD
<script type="text/javascript">
$(document).load(function() {
$('div.notification').fadeIn();
setTimeout(function() {
$('div.notification').fadeOut('slow');
}, 3000);
});
</script>
EOD;
}
I'm also assuming you're including the jQuery library somewhere prior to where this script tag is added. If you're not, make sure you do.
You need to output the javascript within script tags.
Related
I can not get this jQuery to work on page load? I use fancybox 3.
<script>
function openFancybox() {
setTimeout( function() {
$('[data-fancybox data-src="#newsletterFancy"]').trigger('click');
}, 20000);
}
$(document).ready(function() {
var visited = $.cookie('visited');
if (visited == 'yes') {
return false;
} else {
openFancybox();
}
$.cookie('visited', 'yes', { expires: 7 });
$('[data-fancybox data-src="#newsletterFancy"]').fancybox();
});
</script>
I have also added this to my body tag: <body OnLoad="openFancybox()" class="body">
I basically have my pop up in a included file called newsletter.php. The link in my sidebar works fine when i click that. But i want to make it pop up and open on page load with a delay and also for it to set a cookie.
I have also included the cookie js as well:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
This is the line I use in my sidebar link for it to open when you click it:
<a class="buttons" data-fancybox data-src="#newsletterFancy" href="javascript:;">Newsletter Subscribe</a>
Thanks
You are simply not using valid selector. Replace
$('[data-fancybox data-src="#newsletterFancy"]')
with, for example:
$('[data-src="#newsletterFancy"]')
I'm trying to display a download button on an HTML page only when a specific file on the web server is deleted. I thought I'd use a CSS display: none; then a PHP script with a while loop that'd look like this :
while (file_exists("/aaa/file.txt")) {
sleep(5);
}
//set display property of the invisibleLink class to block and continue
The thing is I don't know how to do this last step and every thread I've seen about modifying CSS with PHP doesn't work with my use case.
PHP executes before anything is displayed on the screen, so you are probably not going to be able to do that: the code would simply sleep for 5 and then continue with generating the rest of the html before displaying to the user.
What you might want to do instead is mark the button as display: none and then when the page is done loading have a js function that calls a php page that returns whether the file exists or not. Have the js function loop until the php page says the file is gone, then have the js function display the button and stop looping.
<button type="button" id="test_btn" style="display: none;">Download</button>
<script type="text/javascript">
$(document).ready(function () {
checkFile();
function checkFile() {
$.ajax({
url: '/path/to/file_checker.php',
type: 'GET',
success: function (data) {
if (data === "deleted") { // or whatever you want the response to be
$('#test_btn').show();
}
else {
checkFile(); // you can add a setTimeout if you don't want this running too often
}
}
});
}
}
</script>
Then your file checker php can be something similar to what you had:
if (file_exists("/aaa/file.txt")) {
echo "exists";
}
else {
echo "deleted";
}
Just build the button and hide it with a class like this:
<style>
.hidden{ display:none;}
</style>
<?php
if(!file_exists("path") ){ $class = "hidden" }
echo "<input type='button' class='$class' name='stuff'>woo</button>";
?>
I am just starting with PHP. What i am trying to get to do is change the color of a div from a function that's in an included page. I was able to do this in jquery using load() function.
Here is my current work:
index.php:
include 'functioncontainer.php';
<div style="background-color:#ffff00;">I want this back. color changed</div>
functioncontainer.php:
`<script>
$(document).load(function() {
$('.change').click(function() {
$('div').css('background-color','#06C');
});
});
</script>`
I don't know php but I think you need to echo
echo "<script>
$(document).load(function() {
$('.change').click(function() {
$('div').css('background-color','#06C');
});
});
</script>";
I'm currently writing a php script that is checking if there's no image in a array.
If there is no images, i need a messagebox (i use jquery msgbox) that ask if you wan't to create a product without an image.
If the user clicks yes, how do i then return true so the php code can be executed?
I know php is server side, so I "just" need your suggestion, what's the best solution here.
Currently my code is something like:
<?php if(!isset($_POST['img'] //imagearray)){?>
<script>
$.msgBox({
title: "Sure?",
content: "Add product without images?",
type: "confirm",
buttons: [{ value: "Yes" }, { value: "No" }, { value: "Cancel"}],
success: function (result) {
if (result == "Yes") {
return true;
}else{
return false;
}
}
});
</script>
<?php } ?>
Ok, here is an example,
<script>
$("#my-super-form").submit(function(event) {
if($("#id-of-your-image-input").val()=="")
if(confirm("Add product without image?")) {
return true;
} else {
return false
}
}
return true;
});
</script>
Its not tested, but I think you can figure out how it works.
If you use jQuery, you want to check if image is set after the post.
When user click is sent button, you can use your confirm messageBox, if image not found ^^
it's more intuitive for user.
I have this code that is to fetch a particular item in the database after the user presses a button. If the item is found I would like to display a confirm message via javascript and I don't know how to show it.
After obtaining the item from the database
if(null!=mysqli_fetch_array($res)))
{
echo ""; // how can I call the javascript code here ?
}
and the following confirm box
<script type="text/javascript">
function onConfirm()
{
return confirm("Display this item ?");
}
</script>
Use jquery and ajax to get the value from the database:
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
$.get("ajax.php", function(data){
if(data != "0"){
if(confirm("Display this item ?"))
{
//do something
}
}
});
ajax.php:
//other db code here
if(null!=mysqli_fetch_array($res)))
{
echo "1";
}
else{
echo "0";
}
There are number of ways you can solve this. A good way is to:
Send an ajax request to a page
The page does the mysql stuff and returns(echo in case of PHP) the message
On the callback function use simple way such as alert() to show the message.