Insert Javascript variable into PHP return - php

I am sure this should be easy but I ahve been going crazy trying to get it to work:
return '<img border="0" src="'.$args['Image URL'].'?amount='.$args['invoiceAmount'].'&trans_id='.$args['invoiceNumber'].'&jrox_svalue_1=Sitename:javascript:document.write (sitename);" width="1" height="1">';
Essentially I need to inject the javascript varialbe "sitename" into the querystring value (jrox_svalue_1)for the image.
jrox_svalue_1=Sitename:javascript:document.write (sitename);
Any help would be apprecaited.

This should do the trick:
<script>
document.write("<?php echo '<img border="0" src="' . $args['Image URL'] . '?amount=' . $args['invoiceAmount'] . '&trans_id=' . $args['invoiceNumber'] . '&jrox_svalue_1=' ?>" + sitename + '" width="1" height="1">');
</script>

Hope this would help
<img id="jroxImg" src="'.$args['Image URL'].'?amount='.$args['invoiceAmount'].'&trans_id='.$args['invoiceNumber']." width="1" height="1">
<script type="text/javascript">
var jroxImgObj=document.getElementById('jroxImg');
var jroxImgSrc=jroxImgObj.getAttribute('src');
jroxImgSrc+="&jrox_svalue_1="+siteName;//document.location ??
jroxImgObj.setAttribute('src',jroxImgSrc);
</script>

Related

how to send hidden details when click on image in while loop

this is my code
while ($row = $result->fetch_assoc())
{
$imgpath=$row['image_name'];
$id=$row['id'];
<input type="hidden" name="Id" value="' . $row['Id'] . '" >
here when i click send ID to next page
<img src="'.$imgpath.'" height="170" width="600" title="album-name" class="img-responsive" alt=" " />
}
can i use form for it?
jQuery AJAX will do the job. You just need to attach an event handler function for the click event to the image. We don'it need the hidden element, we will attach $row['id'] to the id attribute of the <img> element, then on the click, we post it via Ajax.
Try this :
//First, make the id attribute of the <img> equal to $id($row['id'])
<img src="'.$imgpath.'" id="$id" height="170" width="600" title="album-name" class="img-responsive" alt=" " />
Then, add the event handler :
$('body').on('click','img',function(){
var id = $(this).attr('id');// Get the id
$.post( "target.php", {id : id}, function( data ) {//Post the id to the target page
//Do whatever..
});
});
try this:
<img src="'.$imgpath.'" height="170" id=id="requestthis" width="600" title="album-name" class="img-responsive" alt=" " />
<input type="hidden" id="hidden_user_id">
and you can use JS like this:
<script type="text/javascript">
$(function() { //ready function
$('#requestthis').on('click', function(e){ //click event
e.preventDefault(); //prevent the click from redirecting you to "submitrequest.php"
var hidden_id = $('#hidden_user_id').val();
var url = "submitrequest.php?hidden_id="+hidden_id;
window.location.replace(url);
//OR
//window.location.href = url;
})
})
you can use .base64_encode this will make the id secure:
<img src="'.$imgpath.'" height="170" width="600" title="album-name" class="img-responsive" alt=" " />

What is the correct syntax to using on click within echo with an img tag?

I am trying to put on click in echo, but it is not working. It shows the image, but when the onclick is selected, it does nothing.
<?
while($row = mysqli_fetch_assoc($result)) {
echo '<img src ="'.$row["img"].'"'.'alt="pic" height="200px" width="250px" align = left onclick="clickedButton()" />';
}
}
else {
echo "no pic upload ";
}
?>
<script type="text/javascript" language="JavaScript">
function clickedButton()
{
window.location = 'index.php';
}
</script>
Alternative Way
Create a class name, use that class name in <script></script>. It will work.
<?
.
echo '<img src ="'.$row["img"].'" class="ClassName" alt="pic" height="200px" width="250px" align = "left" />';
.
?>
JS
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".ClassName").click(function(){
window.location = 'index.php';
});
});
</script>
Maybe it's because you have double quotes in simple quotes (it happened to me once) try adding a backslash in font of the double quotes: \".
But don't do it for $row["img"].

Why my youtube video does not stop?

Here is my code :-
<?php
$sql = "SELECT * FROM era_videos ORDER BY video_id";
$sqlex = mysqli_query($db,$sql);
$m = 1;
while($result = mysqli_fetch_assoc($sqlex))
{
?>
<div class="slide" current_id="<?php echo $m;?>" style="width:300px !important; height:200px !important;">
<object class="youtube" id="videoid<?php echo $m;?>" width="300" height="200"><param name="movie" value="https://www.youtube.com/v/<?php echo $result['urlname'];?>"version=3&hl=en_US&rel=0"> </param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="https://www.youtube.com/v/<?php echo $result['urlname'];?>"version=3&hl=en_US&rel=0" type="application/x-shockwave-flash" width="300" height="200" allowscriptaccess="always" allowfullscreen="true"></embed></object>
</div>
<?php
$m++;
}
?>
jQuery Code :-
jQuery('#iCarouselNext').click(function()
{
var current_id = parseInt($('.current').attr('current_id'));
var previous_id = current_id - 1;
$('#videoid'+previous_id).stopVideo();
});
But it throws an error - Uncaught TypeError: Object [object Object] has no method 'stopVideo'
I found this but no solution Stop a youtube video with jquery?
Thanks in advance
Use
$('#videoid'+previous_id).get(0).stopVideo();
Or
$('#videoid'+previous_id)[0].stopVideo();
Also there is an error in your logic of getting the current_id
var current_id = parseInt($('.current').attr('current_id'));
This will always give the first element's id.

Choose where to insert my youtube video

I have this code which I found on Stack a few weeks ago.
<script type="text/javascript">
$(document).ready(function() {
// I added the video size here in case you wanted to modify it more easily
var vidWidth = 300; // 425;
var vidHeight = 200; // 344;
var obj = '<object width="' + vidWidth + '" height="' + vidHeight + '">' + '<param name="movie" value="http://www.youtube.com/v/[vid]&hl=en&fs=1">' + '</param><param name="allowFullScreen" value="true"></param><param ' + 'name="allowscriptaccess" value="always"></param><em' + 'bed src="http://www.youtube.com/v/[vid]&hl=en&fs=1" ' + 'type="application/x-shockwave-flash" allowscriptaccess="always" ' + 'allowfullscreen="true" width="' + vidWidth + '" ' + 'height="' + vidHeight + '"></embed></object> ';
$('.posthold:contains("youtube.com/watch")').each(function() {
var that = $(this);
var vid = that.html().match(/v=([\w\-]+)/g); // end up with v=oHg5SJYRHA0
that.html(function(i, h) {
return h.replace(/(http:\/\/www.youtube.com\/watch\?v=+\S+\S?)/g, '');
});
if (vid.length) {
$.each(vid, function(i) {
that.append(obj.replace(/\[vid\]/g, this.replace('v=', '')));
});
}
});
});
</script>
It works great at embeding videos from url's. But I have a small problem with it that I have been trying to solve but i keep breaking the code.
Basically I have the following div setup
<div class="grid_10 alpha omega posthold" >
<div class="clearfix">
<div class="grid_2 alpha">
<img src="/images/no-image/logo_default.jpg" width="100" height="100" />
</a></div>
<div class="grid_8 omega">
<h1>Some Name Here</h1>
<p>Some Comment here</p>
</div>
</div>
</div>
Im trying to get the video to appear directly after the closing paragraph tag where it says some comment here. The user enters the video as part of a post. I store the post in a database and when I pull the post out I swap the url from youtube to the embed code. This is a repeating div so there maybe many instances that a video appears. Is this even possible. At the minute the video appears after the last closing div tag.

why does my image roll over behave this way?

My image roll over works... But only one way.
function heartOver(id)
{
if(document.getElementById('heart' + id).src == 'images/heart.png');
{
parent.document.getElementById('heart' + id).src = 'images/unheart.png';
}
if(document.getElementById('heart' + id).src == 'images/unheart.png');
{
parent.document.getElementById('heart' + id).src = 'images/heart.png';
}
}
<img src="images/heart.png" id="heart'.$row['id'].'" alt="Love! width="16" height="16" border="0" onmouseover="heartOver'."('$row[id]')".'; return true;" onmouseout="heartOver'."('$row[id]')".'; return true;">
If i comment out either of the IF statements the other will work but they wont work together...
Note: Tried this with a else if no luck.
Figured it out... Duh: i have if ( ) ; No ; after if...
Put an else between them - otherwise when the first if evaluates as true, it will cause the second if to be evaluated as true also!
Here's a simplified example which also checks the assumption that the img element even exists:
var img=document.getElementById('heart' + id);
if (img)
{
if(img.src == 'images/heart.png')
{
img.src = 'images/unheart.png';
}
else if(img.src == 'images/unheart.png')
{
img.src = 'images/heart.png';
}
}
else
{
alert("Ooooh! No heart"+id+" element found!");
}
Is this correct?
<img src="images/heart.png" id="heart'.$row['id'].'" alt="Love! width="16" height="16" border="0" onmouseover="heartOver'."('$row[id]')".'; return true;" onmouseout="heartOver'."('$row[id]')".'; return true;">
Try with this:
<img src="images/heart.png" id="heart<?php echo $row['id']; ?>" alt="Love!" width="16" height="16" border="0" onmouseover="heartOver(<?php echo $row['id']; ?>)" onmouseout="heartOver(<?php echo $row['id']; ?>)">

Categories