I try to create a javascript to click on the link(id="bigPicLink") once the page load but it not working. New in javascript here. Please help. Thank you.
<?php
// display modal
if (isset($_GET[id]) && $_GET[id] != "" ) {
$result = mysqli_query($dbc, "SELECT * FROM tattoo WHERE `productno` = '$_GET[id]'");
$tattoo = mysqli_fetch_assoc($result);?>
adasdsada
<?php
echo "<script type='text/javascript'>
$(document).ready(function(){
$('#bigPicLink').click();
document.getElementById('bigPicLink').click();
});
</script>";
} ?>
Translate for #mitogh answer :)
$( document ).ready(function() {
$('#bigPicLink').trigger('click')
});
Maybe when you was calling $('#bigPicLink').click() it wasn't create in DOM, so DOM cannot know #bigPicLink is what?
You can try
$(document).ready(function() {
setTimeout(function() {
$('#bigPicLink').click();
}, 1000);
});
or needn't $(document).ready just only setTimeuut
setTimeout(function() {
$('#bigPicLink').click();
}, 1000);
Related
Can anyone help me. I’m trying to make jquery go to function while click on a div. Function works but it goes always on the same ID, first one.
Here is the code:
<?php do { ?>
<div class=“editNews”></div>
<script>
$(function() {
$(“.editNews”).on(“click touchstart”, function(e) {
Here I would like to execute jquery and than go to
window.location = “inserNews.php?id=<?php echo $row_rsNews[“NewsID”]; ?>;
});
e.stopPropagation()
});
});
</script>
<?php } while ($row_rsNews = mysqli_fetch_assoc($rsNews))?>
Thank you very much
i have this code countdown javascript is work fine :
<div id="countdown"></div>
<script type="text/javascript">
$(document).ready(function() {
$('#countdown').countdown('2017/07/11 06:32:11', function(event) {
$(this).html(event.strftime('%H:%M:%S'));
});
});
</script>
but after get the time from database don't work this is the code after get time from database countdown don't show in id countdown
<?php
$auc = $DB_con->prepare("SELECT * FROM `auction` WHER ORDER BY id DESC LIMIT 1");
$auc->execute();
$row = $auc->fetch(PDO::FETCH_ASSOC);
?>
<div id="countdown"></div>
<script type="text/javascript">
$(document).ready(function() {
$('#countdown').countdown(<?php echo $row['timeauc']; ?>, function(event) {
$(this).html(event.strftime('%H:%M:%S'));
});
});
</script>
You have a pair of quotes missing:
$('#countdown').countdown("<?php echo $row["timeauc"]; ?>", function(event) {
$(this).html(event.strftime('%H:%M:%S'));
});
But, to avoid a potential cross-site scripting vulnerability, you should escape the value instead:
$('#countdown').countdown(<?php echo json_encode($row["timeauc"]); ?>, function(event) {
$(this).html(event.strftime('%H:%M:%S'));
});
If nothing is showing up, first make sure $row["timeauc"] actually contains the date string:
var_dump($row["timeauc"]);
I have made a function.php and I included a redirect (to another page) after processing the function.
It works great - I click / function executes and it redirects.
BUT
I want it not to instant redirect and to delay a couple of seconds, since I have a message "Succesuful added.. "
Last part it includes the JS:
//Display ID
echo "<div align='center'> <h4>*Command completed! NR: ".$id_receptie. </h4></div>";
echo "<script type='text/javascript'>
window.onload = function () { top.location.href = 'fisa_service.php?id=" . $id_receptie . "'; };
</script>";
Try the setTimeout function.
setTimeout(function(){
// redirect
}, 2000);
The 2000 are the seconds in milliseconds.
Hope this helps.
You can use the sleep() function in PHP : http://php.net/manual/fr/function.sleep.php
Try next script:
<?php
$timeout = 2; // Timeout in the seconds
$id_receptie = 0;
?>
<div align='center'><h4>*Command completed! NR: <?= $id_receptie ?> </h4></div>
<script type='text/javascript'>
setTimeout(function() {
top.location.href = 'fisa_service.php?id=<?= $id_receptie ?>';
}, <?= $timeout ?>*1000);
</script>
<?php
exit;
I have a jquery script that loads on document ready and I want to display a hidden popup if a user has already clicked a button (button field). But the condition I check is with php code.
<script>
$( document ).ready(function() {
if (<?php $user_fields->field_button['und'][0]['value'] = 1 ?>) {
var popup = document.getElementById("testpopup1").style.visibility = "visible";
alert("x");
}
});
</script>
But this way doesn't work. Is there a way to put the php code inside the if statement of my jquery code or I have to try something else?
You don't need Javascript to do an if and all.
In your HTML
<?php if ($user_fields->field_button['und'][0]['value'] === 1) { ?>
<div id="testpopup1">Your content</div>
<script>alert('x');</script>
<?php } ?>
Save the value of the PHP value in a Javascript variable.
$(document).ready(function() {
var undValue = <?= $user_fields->field_button['und'][0]['value'] ?>;
if (undValue === 1) {
document.getElementById('testpopup1').style.visiblity = 'visible';
alert('x');
}
});
I'm trying to get the value 3 from this link: index.php?subtopic=example&id=3
Normally I would use the $_REQUEST['id'] but I'm facing another situation here.
I got the example1.php:
<script type="text/javascript" src="js/chatbox.js"></script>
...
<div id="chat_box"></div>
And then the chatbox.js:
setInterval( function() {
$('#chat_box').load('chatbox.php');
} , 100 );
And finally the chatbox.php:
echo $_REQUEST['id'];
but I can't get the id value here :/ Please Help!!!
Basically you want to parse the id out of the URL and send it to the chat - let's do this:
<script type="text/javascript">
function getID() {
var tmp=location.href.split('?');
if (tmp.length!=2) return -2;
tmp=tmp[1].split('&');
for (i=0;i<tmp.length;i++) {
var param=tmp[i].split('=');
if (param.length!=2) continue;
if (param[0]!="id") continue;
return parseInt(param[1]);
}
return -3;
}
var chaturl='chatbox.php?id='+getID();
</script>
<script type="text/javascript" src="js/chatbox.js"></script>
...
<div id="chat_box"></div>
...
setInterval( function() {
$('#chat_box').load(chaturl);
} , 100 );
I solved it here:
example1.php
echo "<script type='text/javascript'>
setInterval( function() {
$('#chat_box').load('chatbox.php?id=".$_GET['id']."');
} , 100 );
</script>";
echo '<div id="chat_box"></div>';
and chatbox.php:
echo $_GET['id'];