Zend and Jquery, how to write in zend - php

In header.php file , below is used
<script type="text/javascript" src="http://example.com/library/includes/jQuery142.js">
</script> // jquery
<script type="text/javascript" src="http://example.com/library/includes/jqueryautoiframe.js">
</script> // plugin iFrame Sizing
in view file below code, How do i put below in to zend ?I used below code but not working.
<iframe src="blabla"></iframe>
<script>
$('iframe').iframeAutoHeight(); //iframeAutoHeight is the function in jqueryautoiframe.js
</script>

You need to wait until the document is ready before you can use any js
try this:
<script>
$(function() {
$('iframe').iframeAutoHeight(); //iframeAutoHeight is the function in jqueryautoiframe.js
});
</script>

try
<iframe src="http://google.com"></iframe>
<script type="text/javascript">
$('iframe').iframeAutoHeight(); //iframeAutoHeight is the function in jqueryautoiframe.js
</script>
Your iframe source is 'blabla' did you put it intentionally ??

try
<?php
$this->headScript()
->appendScript(
<<<'BODY'
$('iframe').iframeAutoHeight();
});
BODY
);
?>

Related

jQuery load with php $_GET didn't work

i want to send Get when the link clicked to receive the result in php code
and this what happened
this in php file working perfect
<html>
<a class="cc" href="#">click me</a>
<script src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".cc").click(function () {
$(".body").load('page.php ')
})});
</script>
<section class="body"></section>
</html>
but when i put GET to the href didn't work just Flashing content
<html>
<a class="cc" href="?id=1">click me</a>
<script src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".cc").click(function () {
$(".body").load('page.php ')
})});
</script>
<section class="body"></section>
</html>
In the second case, you really need to stop the <a> from following the link.
$(document).ready(function() {
$(".cc").click(function(e) {
e.preventDefault();
$(".body").load('page.php');
});
});

Pass JQuery variables to php

I want to pass jQuery variable to php file ,
this is my_js.js file
function updates() {
$.getJSON("php/fetch.php", function(data) {
$.each(data.result, function(){
var s_id = this['sender_id'];
});
});
}
and i want to display it here in php file,
<html>
<head><title>Pass jquery var to php file</title>
</head>
<body>
<div> <?php echo $s_id ; ?> </div>
<script type="text/javascript" src="my_js.js"></script>
<script type="text/javascript" src="jquery.js"></script>
</body>
</html>
You might consider using jQuery to set the s_id value in the page.
You can modify your HTML as follows (the important part being the added span element):
<html>
<head><title>Pass jquery var to php file</title>
</head>
<body>
<div><span id="s_id"></span></div>
<script type="text/javascript" src="my_js.js"></script>
<script type="text/javascript" src="jquery.js"></script>
</body>
</html>
And you can use jQuery in your getJSON callback to set the value as follows to find your added span element and modify its text:
function updates() {
$.getJSON("php/fetch.php", function(data) {
$.each(data.result, function(){
$("#s_id").text(this['sender_id']);
});
});
}

Can't figure out jQuery JCombo

I am new in jquery. I was trying to use Jcombo plugin but that one wasn't working for me. Here what I did :
<!doctype html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://www.prodiven.com/jcombo/jquery.jCombo.min.js"></script>
<script type="text/javascript">
$(function() {
/* simple combos */
$("#state1").jCombo("getStates.php");
});
</script>
</head>
<body>
<select id="state1"></select>
</body>
</html>
getStates.php file output was like this:
{"1":"Bangladesh","2":"Arabic"}
Any idea why I can't see drop down selection. Thanks
I got the solution .. It was problem with the plugin. I just noticed that in jCombo.min.js script dataType was "jsonp" I changed it to :
dataType:"json"
now it's working...

moving jquery autocomplete code snippet to script.js file

I'm trying to keep true to the DRY principle by moving my jquery auto complete code to a scripts.js file but i'm having trouble getting the auto complete functionality to work when i move it.
Here's how its setup at the moment.
add form
<head>
<?php
require_once ('includes/connect-db.php');
require_once ('includes/functions.php');
?>
<link href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="includes/js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript">
$('document').ready(function() {
$('#datepickerID').datepicker({
changeYear:true,
changeMonth:true,
dateFormat:'yy-mm-dd'
})
<?php $productArray = autoComplete();?>
$(function() {
var js_products_array = <?php echo json_encode($productArray); ?>;
$( "#autocompleteID" ).autocomplete({
source: js_products_array
});
});
});
</script>
</head>
I'm uncertain as to how to get this to work between the addForm.php and scripts.js when there is embeded php code in the javascript, if that makes sense.
You will have to keep js_products_array outside of the .js file as it contains data from PHP scripts and initilize the autocomplete() on document ready.
so you can keep only
<?php $productArray = autoComplete();?>
<script type="text/javascript">
var js_products_array = <?php echo json_encode($productArray); ?>;
</script>
and in your file.js you can add
$('document').ready(function() {
$('#datepickerID').datepicker({
changeYear:true,
changeMonth:true,
dateFormat:'yy-mm-dd'
})
$( "#autocompleteID" ).autocomplete({
source: js_products_array
});
});

JS/PHP/HTML problem with onload

index.php
<html>
<head>
<script language="JavaScript" src="lol.js.php"></script>
</head>
<?php
//grab product id's who need to be showed
$pids = '1,2,3';
?>
<body onload="update_timers();">
lol.js.php
<script type="text/javascript">
function update_timers()
{
alert('hi');
}
</script>
I'm not sure what I'm missing, but this isn't poping up the alert window. Why is that?
Remove
<script type="text/javascript">
</script>
from the JS file.
The JavaScript error console in your browser should show these tags as syntax errors.
Also, as #Jared points out, you should send a content type header:
<?php header("Content-type: text/javascript"); ?>

Categories