user1036272 user1036272 - 3 months ago 8
PHP Question

javascript functions not working properly under document.ready()

When ever I try adding the second function, the JavaScript ceases to work on the page. Can you guys help with possible error it is? Thanks.

Note: If I comment out the second function, it works fine and the PHP code is an element from CaKePHP.

<script type="text/javascript">
$(document).ready(function() {
$("#is_sublet").click(function() {
$("#sublet_dates").slideToggle();
return false;
});
});

$(document).ready(function() {
$("#custom_rates").click(function() {
$(".avi_specialrates").append($('<?php echo $this->element('custom_price_per_night', array('config' => 'sec')); ?>');
return false;
});
});
</script>

Answer

I think you have a syntax error. Change:

 $(".avi_specialrates").append($('<?php echo $this->element('custom_price_per_night', array('config' => 'sec')); ?>');

by

 $(".avi_specialrates").append($('<?php echo $this->element('custom_price_per_night', array('config' => 'sec')); ?>'));

One parentheses is missing