1

Here is my php code where i am calling the jquery function:

php code

?>
     <script>
        $(function(){
            alertMessage('<?php echo $response ?>');
        });
     </script>
 <?php
   ...more php code...

and the function in javascript file seems like this

function alertMessage(variable){        
$(function(e){
        e.preventDefault();             

        myFunction: jNotify($(this).attr('class'),{
                                VerticalPosition : 'center',
                                HorizontalPosition : 'center'} ); 

});
}

Might be wrong way to do but how can I do this with php parameter in function call. Really Stucked..

Possibly like this Call jquery function from php page, but not working.

7
  • In which function do you want to pass that php parameter ? is it alertMessage(); ?? Commented Apr 21, 2014 at 7:06
  • @AbdUlAziz yes it is the alertMessage(php variable). then use it in the function further. Commented Apr 21, 2014 at 7:15
  • Is alertMessage('<?php echo $variable ?>') ? Commented Apr 21, 2014 at 7:23
  • @X-Man have you tried it like this ? ?> <script> $(function(){ alertMessage('<?php echo $variable ?>'); }); </script> <?php ...more php code... Commented Apr 21, 2014 at 7:49
  • am i defining the function in the js file in the right way or some thing wrong there because its not working @AbdUlAziz Commented Apr 21, 2014 at 8:15

1 Answer 1

1

This type of function call must need an element as parameter. this

myFunction: jNotify($(this).attr('class')

line shows that there must be an element on whom this function is performed. so u can use the above function call as the same but cannot do what you are doing now i.e the

jnotify

action. it must take some element to perform this action.

Sign up to request clarification or add additional context in comments.

1 Comment

Absolutely that's what going wrong with me after all the efforts. Thanks for Correction

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.