This topic is locked

Passing PHP Variable to javascript

4/3/2009 7:41:09 AM
PHPRunner General questions
A
acpan author

Hi,
In the Add form, when user clicks save, i put a java script to ask for confirmation, so i

switch to html mode in the visual editor and modify the save button as follows:
<SPAN class=buttonborder>

<INPUT class=button onclick="if (confirm('Do you really want to send ?'))

frmAdmin.submit(); return false;" type=submit value=Save></SPAN>
The above worked, i.e. each time user clicks save button, it ask: Do you really want to send ?

but i want some variable to be shown as part of the prompt. eg.

"Do you really want to send 20 messages ?
My thinking is:
In my event before add, i have some code to get some value and store in php variable.

eg. $_SESSION["total_record"] = $values["record_cnt"]
And i should include $_SESSION["total_record"] as part of the javascript prompt as follows:
<SPAN class=buttonborder><INPUT class=button onclick="if (confirm('Do you really want to send ?'+$_SESSION["total_record"])); frmAdmin.submit(); return false;" type=submit value=Save></SPAN>
i tried above not working, any advise is appreciated.
acpan

Admin 4/3/2009

Use the following:

<SPAN class=buttonborder><INPUT class=button onclick="if (confirm('Do you really want to send

{$num_of_messages} messages?')); frmAdmin.submit(); return false;" type=submit value=Save></SPAN>


In BeforeDisplay event assign a value to num_of_messages variable:

$xt->assign('num_of_messages', 20);


More info:

http://www.xlinesoft.com/phprunner/docs/smarty_templates.htm

A
acpan author 4/3/2009

Thanks, but it shows empty at the prompt.

  1. At BeforeAdd event, i assign the form value $values["record_cnt"] to $_SESSION["total_record"].
  2. Then at the BeforeShowAdd event, i assign

    it to: $xt->assign('num_of_messages', $_SESSION["total_record"]);
    it does not work with the above. it does work if i assign a static value at BeforeShowAdd event

    which defit the pupose since i need to calculate the number at BeforeAdd event.
    i read the help link provided and tried, still can't get it right.
    I think i need to have a way to pass variable from the BeforeAdd event

    to BeforeShowAdd event. Any further advice?
    Thanks

    acpan

Admin 4/4/2009

I recommend to post your application to Demo Account (use 'Demo Account' button on the last screen in program). Then open a ticket at http://support.xlinesoft.com sending your Demo Account URL for investigation.

A
acpan author 4/5/2009

Hi Sergey, Thanks for your reply.
I think it could be a yes and no answer, no need to publish to demo account.
You example assign a static value 20:
$xt->assign('num_of_messages', 20);
I want to assign a variables calculated in BeforeAdd event than assign in BeforeShow Event, eg.:
$xt->assign('num_of_messages', $my_beforeadd_variable);
How to achieve that ? or it's not possible to do it.
Thanks

Dex Pan

A
acpan author 4/5/2009

Hi Sergey, Thanks for your reply. Let me rephrase it.
Your example assigned a static value 20 at beforeDisplay event:
$xt->assign('num_of_messages', 20);
But I want to assign a variable, instead of static value as i need

to calculate in BeforeAdd event first than assign in BeforeShow Event as you suggested, eg.:
In BeforeAdd event:
$my_beforeadd_variable = $a + $b;
Then in BeforeShow event:
$xt->assign('num_of_messages', $my_beforeadd_variable);
I tried above but $my_beforeadd_variable is empty value at the end when i print on screen.

Is it possible to do this at all ?
Thanks

Dex Pan

Admin 4/5/2009

If you need help with this you need to post your application to Demo Account (use 'Demo Account' button on the last screen in program). Then open a ticket at http://support.xlinesoft.com sending your Demo Account URL for investigation.

L
laonian 4/15/2009

acpan,
May I ask to share your solution to the question? Thanks.

A
acpan author 4/21/2009

acpan,

May I ask to share your solution to the question? Thanks.


I posted to demo but it ask for support account.

i had never use the support service since i bought the phpr,

guess it's expired so i did not proceed.
i had put this aside since it's not urgent but any help from

any member appreciated.