How to use jQuery or JavaScript in PHP
Some time we have a such type of logic in which we want to use jQuery within PHP code. It is very useful and sometime you can perform
a very difficult task by using jQuery and PHP in no time. Here i am using jQuery/JavaScript code for showing and hiding of any div.
Basically here i am trying to show errors after validating a form on server side.
if($first_name==”” || $first_name==null)
{
?>
<script>
$(document).ready(function(){
$(“.contact2”).hide();
$(“.names2”).show();
});
</script>
<?php
}
elseif($last_name==”” || $last_name==null)
{
?>
<script>
$(document).ready(function(){
$(“.contact2”).hide();
$(“.name2”).show();
});
</script>
<?php
}
elseif(!preg_match($email_exp,$enq_email))
{
?>
<script>
$(document).ready(function(){
$(“.contact2”).hide();
$(“.emails2”).show();
});
</script>
If you still find any problem just mention it in comment i will try to resolve it.