By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,599 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,599 IT Pros & Developers. It's quick & easy.

javascript within php

P: 77
hello all, i have a question..can script of javascript (variable of js or html form)stored within tag php or php command???

thanks


kind regards, maminx
Jul 29 '08 #1
Share this Question
Share on Google+
6 Replies


10K+
P: 13,264
Give an example of what you mean.
Jul 29 '08 #2

P: 77
Give an example of what you mean.

the point is i need to call a javascript method within php code, but with no user interaction. i.e. no click of a button, no user input, nothing.


this is the example

i have an input form

[HTML]<input name="textfield" type="text" size="10" value="<?php echo $this->ProjectPraBp_model->getProjectPraBpDate("025");?>">
[/HTML]

there's value "025" (bold)...i want that value is from javascript variable / form html object, is it possible??

thanks

maminx
Jul 29 '08 #3

P: 77
the point is i need to call a javascript method within php code, but with no user interaction. i.e. no click of a button, no user input, nothing.


this is the example

i have an input form

[HTML]<input name="textfield" type="text" size="10" value="<?php echo $this->ProjectPraBp_model->getProjectPraBpDate("025");?>">
[/HTML]

there's value "025" (bold)...i want that value is from javascript variable / form html object, is it possible??

thanks

maminx

is there anyone can help me with this issue??
Jul 31 '08 #4

acoder
Expert Mod 15k+
P: 16,027
This won't be possible directly. PHP is server-side. It runs and the page finishes execution whereas JavaScript is client-side.

The way to solve your problem would be to make an Ajax request after the page loads with the JavaScript variable. However, having said that, if you already know the JavaScript value, just replace it in the PHP code.
Jul 31 '08 #5

P: 77
This won't be possible directly. PHP is server-side. It runs and the page finishes execution whereas JavaScript is client-side.

The way to solve your problem would be to make an Ajax request after the page loads with the JavaScript variable. However, having said that, if you already know the JavaScript value, just replace it in the PHP code.

yes i think it needs ajax, and of i of course i don;t know the javascript value so i can't replace it with the php code..the value is generated with html form or variable of javascript..

But my issue now is because i'm using framework php (codeigniter), than i can't just put the ajax into the php code, there's a rule of framework..

anyway, thanks a lot

kind regards, maminx
Aug 1 '08 #6

acoder
Expert Mod 15k+
P: 16,027
It must allow some JavaScript which you can put in the head and call when required, e.g. onclick of a button.

If that's not possible, submit the form with a hidden value and set the input value using PHP.
Aug 1 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.