Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

php in javascript

 
   Database Forums (Home) -> PHP RSS
Next:  how this query should be in mysql 5  
Author Message
juicy

External


Since: Feb 12, 2006
Posts: 7



(Msg. 1) Posted: Mon Apr 24, 2006 4:11 am
Post subject: php in javascript
Archived from groups: comp>lang>php (more info?)

I have create a checkbox,call getS function in onclick event. I append
value of variable output with value $text. It works well but when I
changed value of $text to a paragraph of text, it will occur error on the
page. Please advise. Thanks.

<script language = "javascript">
<?php $text = "testing"; ?>

function getS (id){
var output = "";
if (document.getElementById("id").checked)
{
output = output + <? echo $text; ?> ;
}}
</script>

 >> Stay informed about: php in javascript 
Back to top
Login to vote
fletch

External


Since: Apr 11, 2006
Posts: 5



(Msg. 2) Posted: Mon Apr 24, 2006 4:11 am
Post subject: Re: php in javascript [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

You need to learn about the request resonse model. php is run to
produce html(& javascript) which is then sent to the browser. The
broser then runs the html (& javascript). So your code will be
delivered to the browser as

<script language = "javascript">

function getS (id){
var output = "";
if (document.getElementById("id").checked)
{
output = output + testing ; // <- error testing is not a variable.
}}

</script>

 >> Stay informed about: php in javascript 
Back to top
Login to vote
fletch

External


Since: Apr 11, 2006
Posts: 5



(Msg. 3) Posted: Mon Apr 24, 2006 4:11 am
Post subject: Re: php in javascript [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

You need to have valid javascript code, which is not happening when you
have several lines in text. You want to get to
output +="Line1\nLine2\nLine3\n"; // += is the same as a=a+
so
<? function jsencode($str)
{
return implode('\n',explode("\n",$str)); //Could use str_replace -
probably better.
}?>

output+="<? echo jsencode($text); ?>";
 >> Stay informed about: php in javascript 
Back to top
Login to vote
juicy

External


Since: Feb 12, 2006
Posts: 7



(Msg. 4) Posted: Mon Apr 24, 2006 4:47 am
Post subject: Re: php in javascript [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Fletch wrote:
>You need to learn about the request resonse >model. php is run to
>produce html(& javascript) which is then sent >to the browser. The
>broser then runs the html (& javascript). So >your code will be
>delivered to the browser as

><script language = "javascript">
>function getS (id){
>var output = "";
>if (document.getElementById("id").checked)
>{
> output = output + testing ; // <- error >testing is not a variable.
>}}
></script>

Sorry, I have mistype the code, it should be

output = output + "<? echo $text; ?>";

if I assign $text a short text, it will OK. But if $text is a paragraph/
multiple line of string, it will occur error on the page.

Please give idea on what has happen..
Thanks.
 >> Stay informed about: php in javascript 
Back to top
Login to vote
Bart the bear

External


Since: May 09, 2005
Posts: 4



(Msg. 5) Posted: Mon Apr 24, 2006 5:10 am
Post subject: Re: php in javascript [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

juicy wrote:
>it will occur error on the page. Please advise. Thanks.

All your bases are belong to us!
 >> Stay informed about: php in javascript 
Back to top
Login to vote
juicy

External


Since: Feb 12, 2006
Posts: 7



(Msg. 6) Posted: Mon Apr 24, 2006 9:22 pm
Post subject: Re: php in javascript [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Fletch wrote:
>You need to learn about the request resonse >model. php is run to
>produce html(& javascript) which is then sent >to the browser. The
>broser then runs the html (& javascript). So >your code will be
>delivered to the browser as

><script language = "javascript">
>function getS (id){
>var output = "";
>if (document.getElementById("id").checked)
>{
> output = output + testing ; // <- error >testing is not a variable.
>}}
></script>

Sorry, I have mistype the code, it should be

output = output + "<? echo $text; ?>";

if I assign $text a short text, it will OK. But if $text is a paragraph/
multiple line of string, it will occur error on the page.

Please give idea on what has happen..
Thanks.
 >> Stay informed about: php in javascript 
Back to top
Login to vote
juicy

External


Since: Feb 12, 2006
Posts: 7



(Msg. 7) Posted: Mon Apr 24, 2006 10:05 pm
Post subject: Re: php in javascript [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Fletch wrote:
>You need to have valid javascript code, which >is not happening when you
>have several lines in text. You want to get to
>output +="Line1\nLine2\nLine3\n"; // += is the >same as a=a+
>so
><? function jsencode($str)
>{
> return implode('\n',explode
>("\n",$str)); //Could use str_replace -
>probably better.
>}?>
>output+="<? echo jsencode($text); ?>";


But why if I pass the paragraph of text from onclick event on a checkbox,
to show it on textarea, it can perform well although the text is a
paragraph.

<td ><input type=checkbox name="chksur2"
onclick="getSurcharge('duties',this.value)" value="<? echo $strSurcharge1;
?>">

<script language="JavaScript">
function getSurcharge(id, value)
{
document.getElementById(id).value= value;
//to show text on a textarea
}
</script>

<?php $strSurcharge1 = " (paragraph of text) ";
?>
 >> Stay informed about: php in javascript 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 1366



(Msg. 8) Posted: Mon Apr 24, 2006 10:06 pm
Post subject: Re: php in javascript [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

juicy wrote:
> Fletch wrote:
>
>>You need to learn about the request resonse >model. php is run to
>>produce html(& javascript) which is then sent >to the browser. The
>>broser then runs the html (& javascript). So >your code will be
>>delivered to the browser as
>
>
>><script language = "javascript">
>>function getS (id){
>>var output = "";
>>if (document.getElementById("id").checked)
>>{
>> output = output + testing ; // <- error >testing is not a variable.
>>}}
>></script>
>
>
> Sorry, I have mistype the code, it should be
>
> output = output + "<? echo $text; ?>";
>
> if I assign $text a short text, it will OK. But if $text is a paragraph/
> multiple line of string, it will occur error on the page.
>
> Please give idea on what has happen..
> Thanks.
>
>
>
>
>
>
>

Looks like a javascript problem to me. Try a javascript newsgroup.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex DeleteThis @attglobal.net
==================
 >> Stay informed about: php in javascript 
Back to top
Login to vote
Display posts from previous:   
   Database Forums (Home) -> PHP All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]