How to pass PHP variable value to javascript variable in view.edit.php?

Hello everyone, I want to pass $bean->id value of Case module to a javascript variable in view.edit.php file of "Case" module. I want to know, whether it is possible without using AJAX and if it is, then I would like to know, HOW TO?
Parents
  • I assume the JavaScript is for edit view

    The current record id is available in a hidden field called record

    you can retrieve it in your JavaScript using $('[name="record"]').val()
Reply
  • I assume the JavaScript is for edit view

    The current record id is available in a hidden field called record

    you can retrieve it in your JavaScript using $('[name="record"]').val()
Children
  • Hey mike, sorry I mistakenly wrote $bean->id. I want to retrieve id of relate field account and using that id I want to retrieve all field of that account and from that I want to use type of that account and store that in javascript variable. Example:
    $oAccount = new Account();
    $oAccount->retrieve($bean->accounts_cases_1_name);
    $type_of_account = $oAcccount->type;
    And I want to use value of $type_of_account in javascript variable. Is it possible?
  • I think you are going to need to do an ajax call

    The other possible option depending what you actually need is to do the call in view.edit then store the information in hidden fields created in editviewdefs


  • Hi,
    If js you are writing in view.edit.php you can assign the value $type_of_account directly to a javascript varible.

    $script=<<EOC
    <script type="text/javascript">
               //here we can use the $type_of_account variable directly
               var account_type='$type_of_account ';
    </script>
    EOC;


    I am not sure this is what you are asking for:)

  • this is what I am asking, but I tried that but doesn't work....have you tried that first?
  • Yes its working for me.Is the script executing for you?
  • $script=<<EOC
    <script type="text/javascript">
               //here we can use the $type_of_account variable directly
               var account_type='$type_of_account ';
    </script>
    EOC;

    echo $script variable after parent::display(); method in the view.edit.php file

  • if I am  using that javascript variable in alert function, it doesn't show me that value of php variable after assigning php variable to javascript variable. This my script

    $script=<<EOC
    <script type="text/javascript">
               var bn='$bean';
               alert(bn);
    </script>
    EOC;

    I am getting blank alert......???