This is my slider.php page in which content of ajax.php file is loaded through ajax.
var xmlhttp;
function showtemplate(temp)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState===4 && xmlhttp.status===200) {
var div = document.getElementById('contain');
div.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET', 'ajax.php?section='+temp, true);
xmlhttp.send();
}
The content of ajax.php file is loading into the contain div.
This is my ajax.php file where I am using jquery to slideshow images.
<?php
$final=$_REQUEST['section'];
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js?ver=1.4.2"></script>
<script type="text/javascript">
$(function()
{
var currentIndex = 0,
var items = $('.container div'),
var itemAmt = items.length;
function cycleItems()
{
var item = $('.container div').eq(currentIndex);
items.hide();
item.css('display','inline-block');
}
var autoSlide = setInterval(function()
{
currentIndex += 1;
if (currentIndex > itemAmt - 1)
{
currentIndex = 0;
}
cycleItems();
}, 3000);
$('.next').click(function() {
clearInterval(autoSlide);
currentIndex += 1;
if (currentIndex > itemAmt - 1)
{
currentIndex = 0;
}
cycleItems();
});
$('.prev').click(function() {
clearInterval(autoSlide);
currentIndex -= 1;
if (currentIndex < 0) {
currentIndex = itemAmt - 1;
}
cycleItems();
});
});
</script>
<section class="demo">
<button class="next" id="next">Next</button>
<button class="prev" id="prev">Previous</button>
<div class="container">
<div style="display: inline-block;">
<img src='images/<?php echo $final;?>/image1.jpg'/>
</div>
<div>
<img src='images/<?php echo $final;?>/image2.jpg'/>
</div>
<div>
<img src='images/<?php echo $final;?>/image3.jpg'/>
</div>
<!--<span u="arrowleft" class="jssora12l" style="width: 41px; height: 50px; top: 110px; left: 2px;"> </span>
<span u="arrowright" class="jssora12r" style="width: 41px; height: 50px; top: 110px; right: 5px"> </span>-->
</div>
but when I clicked on next and previous button it doesn't work. Please help me out.
My code is working now. I simply request section and display it as thumbs without using jquery.
<?php
$final=$_REQUEST['section'];
include "slider/relatedcat.php";
?>
<div style="margin-bottom: 10px; font-size: 18px;font-family: 'Roboto Slab',serif;margin-top: -7px">Choose <?php echo ucwords($final);?> Card Template.</div>
<?php
for($i=1;$i<=count($template);$i++)
{
?>
<div id="thumb<?php echo $i;?>" onclick='showimage("template<?php echo $i; ?>","<?php echo $final;?>");' style='box-shadow: rgba(34, 25, 25, 0.4) 0px 1px 3px;border-radius: 15px;width: 150px !important;height: 150px !important;top: 0px;float:left;margin-right: 20px;margin-bottom:15px;overflow: hidden;transform: perspective(2000px);background: white;cursor: pointer;'>
<img alt='<?php echo ucwords($final);?>' u='image' src='images/<?php echo $final;?>/template<?php echo $i?>.jpg' style='width:100%;height:100%;' />
</div>
<?php
}
?>
If you want to use jquery in ajax loaded div then you have to redefine jquery function on success of ajax function like below code :
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState===4 && xmlhttp.status===200) {
var div = document.getElementById('contain2');
div.innerHTML = xmlhttp.responseText;
$('#resize').draggable({containment: '#main'}).resizable({maxWidth:350, maxHeight:333});
$('#msgvisible').draggable({containment: '#main'});
//alert(xmlhttp.responseText);
document.getElementById('stylepart').style.display="block";
}
}
Related
Selecting the multiple image from the input tag after that I am previewing the selected image but when I click on that image it should delete from the input tag it does not select that picture any more. But in my case that picture is removing only in preview not in input. And save it into database
Here is the code
<?php
include_once 'Functions.php';
$connect=new Connection();
$link=$connect->Connect();
print_r($_FILES['fil']['name']);
?>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
var image=('')
('input[type="file"]'). change(function(e){
var fileName = e. target. files[0]. name;
alert('The file "' + fileName + '" has been selected.' );
});
$(function() {
var imagesPreview = function(input,placeToInsertImagePreview) {
if (input.files) {
var filesAmount = input.files.length;
for (i = 0; i < filesAmount; i++) {
var reader = new FileReader();
reader.onload = function(event) {
$($.parseHTML('<img class="picture" width="70" name="multipic">')).attr('src', event.target.result).appendTo(placeToInsertImagePreview);
$('.picture').click(function(){
$(this).remove();
});
}
reader.readAsDataURL(input.files[i]);
}
}
};
$('#gallery-photo-add').on('change', function() {
imagesPreview(this,'div.gallery');
});
});
});
</script>
</head>
<body>
<form name="update" enctype='multipart/form-data' method="POST">
<input type="file" name="fil[]" multiple id="gallery-photo-add" class="a1">
<div class="gallery"></div>
<input type="submit" name="btnupdate" value="Update" />
</form>
</body>
</html>
Here is HTML Code :
<div class="container">
<form id="fileupload" action="#" method="POST" enctype="multipart/form-data">
<div class="row files" id="files1">
<h2>Files 1</h2>
<span class="btn btn-default btn-file">
Browse <input type="file" name="files1" multiple />
</span><br/>
<ul class="fileList"></ul>
</div>
<div class="row">
<button type="x" id="uploadBtn" class="btn primary start">Start upload</button>
</div>
<div class="row">
<div class="span16">
<table class="zebra-striped"><tbody class="files"></tbody></table>
</div>
</div>
</form>
</div>
Here is CSS Code :
.btn-file {
position: relative;
overflow: hidden;
}
.btn-file input[type=file] {
position: absolute;
top: 0;
right: 0;
min-width: 100%;
min-height: 100%;
font-size: 100px;
text-align: right;
filter: alpha(opacity=0);
opacity: 0;
outline: none;
background: white;
cursor: inherit;
display: block;
}
Here is jQuery Code :
$.fn.fileUploader = function (filesToUpload, sectionIdentifier) {
var fileIdCounter = 0;
this.closest(".files").change(function (evt) {
var output = [];
for (var i = 0; i < evt.target.files.length; i++) {
fileIdCounter++;
var file = evt.target.files[i];
var fileId = sectionIdentifier + fileIdCounter;
filesToUpload.push({
id: fileId,
file: file
});
var removeLink = "<a class=\"removeFile\" href=\"#\" data-fileid=\"" + fileId + "\">Remove</a>";
output.push("<li><strong>", escape(file.name), "</strong> - ", file.size, " bytes. ", removeLink, "</li> ");
};
$(this).children(".fileList")
.append(output.join(""));
//reset the input to null - nice little chrome bug!
evt.target.value = null;
});
$(this).on("click", ".removeFile", function (e) {
e.preventDefault();
var fileId = $(this).parent().children("a").data("fileid");
// loop through the files array and check if the name of that file matches FileName
// and get the index of the match
for (var i = 0; i < filesToUpload.length; ++i) {
if (filesToUpload[i].id === fileId)
filesToUpload.splice(i, 1);
}
$(this).parent().remove();
});
this.clear = function () {
for (var i = 0; i < filesToUpload.length; ++i) {
if (filesToUpload[i].id.indexOf(sectionIdentifier) >= 0)
filesToUpload.splice(i, 1);
}
$(this).children(".fileList").empty();
}
return this;
};
(function () {
var filesToUpload = [];
var files1Uploader = $("#files1").fileUploader(filesToUpload, "files1");
$("#uploadBtn").click(function (e) {
e.preventDefault();
var formData = new FormData();
for (var i = 0, len = filesToUpload.length; i < len; i++) {
formData.append("files", filesToUpload[i].file);
}
$.ajax({
url: "",
data: formData,
processData: false,
contentType: false,
type: "POST",
success: function (data) {
alert("DONE");
files1Uploader.clear();
},
error: function (data) {
alert("ERROR - " + data.responseText);
}
});
});
});
Try above code. Hope this will help
I 've used the below code to convert text to emoticons in javascript,
function add_smile($text) {
var $text=$text;
function RegExpEscape(text) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
var emoticons = {
':)' : 'images/smileys/angry.gif',
':(' : 'images/smileys/sad.gif',
';)' : 'images/smileys/wink.gif'
}
var result =$text;
var emotcode;
var regex;
for (emotcode in emoticons)
{
regex = new RegExp(RegExpEscape(emotcode), 'gi');
result = result.replace(regex, function(match) {
var pic = emoticons[match.toLowerCase()];
if (pic != undefined) {
return '<img src="' + pic + '"/>';
} else {
return match;
}
});
}
$('#editor-textarea').val($('#editor-textarea').val() + " " + result);
}
In my view,
<textarea name="content" class="editor-textarea" id="editor-textarea">
</textarea>
<?php foreach($smiles as $k=>$v) : ?>
<button type="button" class="nobutton" onclick="add_smile('<?php echo $k ?>')"><?php echo $v ?></button>
<?php endforeach; ?>
The javascript function now replace the text with <img src="images/smileys/angry.gif"> as text not display as image.How do I solve this?
This is how textarea works - it displays and allows you to edit text. If you need a WYSIWYG control, think of using contentEditable (https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Editable_content)
$("button.make-editable").on("click", function() {
$("#inputbox")
.attr('contenteditable', 'true')
.html("<b>this is bold</b>this is smiley \
<img src='https://upload.wikimedia.org/wikipedia/commons/e/e0/SNice.svg' />");
});
$("button.make-standard").on("click", function() {
var inputbox = $("#inputbox");
inputbox.attr('contenteditable', 'false');
console.log(inputbox.html());
});
#inputbox {
border: 1px solid red;
padding: 10px;
}
#inputbox img {
width: 12px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="inputbox">
This text should become editable.
</div>
<button class='make-editable'>Make DIV editable</button>
<button class='make-standard'>Remove "contentEditable", get value</button>
I have a modal on each tenant on a table for their receipt and i only want to print the modal, but the problem is the print only works on the first tenant, and does not work on the other tenants on the table.
<script>
document.getElementById("btnPrint").onclick = function () {
printElement(document.getElementById("printThis"));
var modThis = document.querySelector("#printSection .modifyMe");
modThis.appendChild(document.createTextNode(""));
window.print();
}
function printElement(elem) {
var domClone = elem.cloneNode(true);
var $printSection = document.getElementById("printSection");
if (!$printSection) {
var $printSection = document.createElement("div");
$printSection.id = "printSection";
document.body.appendChild($printSection);
}
$printSection.innerHTML = "";
$printSection.appendChild(domClone);
}
</script>
(html)
<div id="printThis" class=" modifyMe">
<h3 class="modal-title text-center" id="myModalLabel">
(css)
#media print {
body * {
visibility:hidden;
}
#printSection, #printSection * {
visibility:visible;
}
#printSection {
position:absolute;
left:0;
top:0;
}
I have a page that has a form on it, when I click a button on the page it sends 3 variables to a layer(page_ref, template_ref, and box_id) via a javascript call.
Then with ajax I get some content from the mysql db with the variables and insert this into a text area on the layer.
The layer has a save button and when I click that I want to save the content of the textarea back to the db.
I can fill the textarea from the db no problem but am having problems pushing is back to the db.
The problem I have is sending the javascript variables to the ajax update page as they need to be passed to php varriables.
heres what I have
on the main page I call a javascript function
edit_box('show',i,'<? echo $page_ref; ?>','<? echo $template_ref; ?>');
in the layer I have this
<style type="text/css">
#popupbox
{
padding:0;
width: 99%;
height: auto;
margin: 0px auto;
position:absolute;
background: #FBFBF0;
border: solid #000000 2px;
z-index: 9000;
font-family: arial;
visibility: hidden;
}
</style>
<script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script>
<script>
//Browser Support Code
function get_edit_content(box_id,page_ref,template_ref)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("edit_content").innerHTML=xmlhttp.responseText;
var area1 = new nicEditor({fullPanel : true}).panelInstance("edit_content",{hasPanel : true});
}
}
var queryString = "?box_id=" + box_id + "&page_ref=" + page_ref + "&template_ref=" + template_ref;
xmlhttp.open("GET","get_content.php" + queryString,true);
xmlhttp.send();
}
$("#sub").click( function()
{
$.post( $("#myForm").attr("action"),
$("#myForm :input").serializeArray(),
function(info)
{
$("#result").html(info);
});
clearInput();
});
$("#myForm").submit( function()
{
return false;
});
function clearInput()
{
$("#myForm :input").each( function()
{
$(this).val('');
});
}
function edit_box(showhide,box_id,page_ref,template_ref)
{
if(showhide == "show")
{
get_edit_content(box_id,page_ref,template_ref);
document.getElementById('popupbox').style.visibility="visible";
}
else if(showhide == "hide")
{
document.getElementById('popupbox').style.visibility="hidden";
}
}
</script>
<div id="popupbox">
<form id="myForm" action="update_textarea.php" method="post">
<input type="hidden" name="page_ref" value="<? echo $page_ref; ?>" />
<input type="hidden" name="template_ref" value="<? echo $template_ref; ?>" />
<input type="hidden" name="box_id" value="<? echo $box_id; ?>" />
<textarea name="edit_content" id="edit_content" style="width: 500px; height:500px;"></textarea>
<center>close</center>
<button id="sub">Save</button>
</form>
</div>
then I have get_contents page
<?php
include("connect.php");
$page_ref = $_GET['page_ref'];
$template_ref = $_GET['template_ref'];
$box_id = $_GET['box_id'];
$sql = "SELECT * FROM site_content WHERE page_ref='$page_ref' AND template_ref='$template_ref' AND box_id='$box_id' AND box_type='text'";
$result = mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo "<p>".$row['content']."</p>";
}
?>
and finally the update_textarea page
<?
include("connect.php");
$page_ref = $_POST['page_ref'];
$template_ref = $_POST['template_ref'];
$box_id = $_POST['box_id'];
$edit_content = $_POST['edit_content'];
if(mysql_query("UPADTE site_content SET content='$edit_content' WHERE page_ref='$page_ref' AND template_ref='$template_ref' AND box_id='$box_id' AND box_type='text'"))
{
echo "Successfully Inserted";
}
else
{
echo "Insertion Failed";
}
?>
I realised that i needed to set the values of the hidden inputs in the ajax call after
document.getElementById("edit_content").innerHTML=xmlhttp.responseText;
by adding
document.getElementById("box_id").value = box_id;
etc
What I have at the moment is a simple Facebook app that has pulled the video information from a YouTube channel.
Just now, I embed the first video of the response from YouTube into the placeholder along with the title, views and description and all videos (including the first) are displayed below the div that holds the embedded video.
Then, when the user clicks any of the video thumbnails, that video is then embedded in the placeholder div.
I can get this to work by hard-coding the id of the video inside the YouTube associative array but I can't figure out how to use the id variable with PHP in the last line of my jQuery code.
Here is my current code:
$url = 'http://gdata.youtube.com/feeds/api/videos?max-results=20&alt=jsonc&orderby=published&format=5&safeSearch=none&author=CHANNELID&v=2';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $url);
$body = curl_exec($ch);
curl_close($ch);
$data = json_decode($body, true);
?>
<div id="placeholder" style="font-family:Helvetica; max-width:500px; margin:0 0 20px 0;">
<div id="player"><iframe width="480" height="274" src="https://www.youtube.com/embed/<?php echo $data['data']['items'][0]['id']; ?>" frameborder="0" allowfullscreen></iframe></div>
<div class="title" style=" font-size:14px; font-weight:bold; color:#3B5998; margin:2px 0 3px 0;"><?php echo $data['data']['items'][0]['title']; ?> </div>
<div class="views" style="color:#BBB; font-size:12px;"><?php echo $data['data']['items'][0]['viewCount'];?> views</div>
<div class="description" style="font-size:14px;"><?php echo $data['data']['items'][0]['description'];?></div>
<div class="hr" style="padding:5px 0 0 0; float:left; border-bottom: 1px solid #96CC90; width:480px;"></div>
</div>
<?php
foreach($data['data']['items'] as $item) {
$id = $item['id'];
$description = $item['description'];
$description = str_replace('uk.opticalexpress.com', '', $description);
$description = str_replace('-', '', $description);
$description = trim($description);
$thumb = $item['thumbnail']['sqDefault'];
$i = 0;
?>
<div class="video" id="<?php echo $i; ?>" style="font-family:Helvetica; float:left; max-width:150px; min-height:130px; margin:0 0px 20px 10px;">
<div class="thumb" style="position:relative; left:0; top:0;">
<img src="<?php echo $item['thumbnail']['sqDefault'];?>" title="<?php echo $description;?>" style="position:relative; top:0; left:0px;"/>
<img src="../images/play-thumb.png" style="position:absolute; top:30px; left:45px;"/>
</div>
<div class="title" style="font-size:14px; font-weight:bold; color:#3B5998; margin:2px 0 3px 0;"><?php echo $item['title']; ?> </div>
<div class="views" style="font-size:12px;"><?php echo $item['viewCount'];?> views</div>
</div>
<?php
$i++;
}
?>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.video').click(function() {
var id = $(this).attr('id');
$('#placeholder').fadeOut('slow');
$('#placeholder').html('<div id="player"><iframe width="480" height="274" src="https://www.youtube.com/embed/<?php echo $data['data']['items'][1]['id']; ?>" frameborder="0" allowfullscreen></iframe></div>');
$('#placeholder').fadeIn('slow');
});
});
</script>
Sorry for the wall of text (and inline css)!
Difficult... I would watch the click event on .video with jQuery, then carry out a GET request to a PHP file on the server (RESTish) which would generate the HTML needed for the iframe, then set the #video html to the html you just received. Might work...
Another possibility, is to load all the iframes, then on .video click just show the one matching the same unique id or something. This would mean more load time for your users though, best to go with the AJAX type approach.
you can use the ajax by doing this, i have done it like this way, hope this will also work for you.
<div id="video1" class=".temp"></div>
<script type="text/javascript">
$(document).ready(function() {
$('.temp').click(function() {
var currentId = $(this).attr('id');
showVideo(currentId);
});
};
function showVideo(str)
{
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("VideoFrameDiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","inc/AjaxOnClickValues.php?id="+str,true);
xmlhttp.send();
}
</script>