Solved

HTML To Javascript function??

Posted on 2004-04-06
4
292 Views
Last Modified: 2013-12-16
Hi,

I have a php variable that generated by spaw editor.
I have javascript function that save a text into an xml file. (i.e. function  GetContent(text)).
The problem is when I pass the php variable to the getfunction(text) does not work if it contains an HTML tags.(i.e. If does not conatin HTML tags it works correctly).
 


This is my javascript function:

function GetContent(text) {


element_id = <?=$doc?> * 1000 + 1 ;
title_count = 0;
title_is_first = true ;

xml_doc="<DOC>";

         
          str = new String;
          str = text;
         
          xml_doc +='<PAR ID="'+element_id+'"><![CDATA[' + str + "]]></PAR>" ;
          element_id ++;
         
     
xml_doc += "</DOC>"


     document.edit.xml_doc.value = xml_doc ;
     document.edit.submit();
}


This the for the function:


<input type="button" onClick="GetContent('<? echo $text; ?>')" value="      U p d a t e          "></input>


Thanks for your response
0
Comment
Question by:ALNMOO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 10769998
Put in fron of your function some global var.
Like this:

var theText = '<? echo $text; ?>';

function GetContent(text) {...


And your button is then like this:
<input type="button" onClick="GetContent(theText)" value="      U p d a t e          ">

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10770017
Or if you have several text contents, then put them beside your button.

Like this:
<script>text1='<? echo $text; ?>'</script>
<input type="button" onClick="GetContent(text1)" value="      U p d a t e          ">
<script>text2='<? echo $text2; ?>'</script>
<input type="button" onClick="GetContent(text2)" value="      U p d a t e  Two         ">

0
 
LVL 25

Accepted Solution

by:
devic earned 500 total points
ID: 10770325
<?
$text = str_replace("'", "&#039;", $text;);
$text = str_replace("\"", "&quot;", $text;);
?>
<input type="button" onClick="GetContent('<? echo $text; ?>')" value="      U p d a t e          "></input>
0
 
LVL 25

Expert Comment

by:devic
ID: 10770349
so above example was simple replace on server.

and here client solution:
====================
<span id=cont><? echo $text; ?></span>
<input type="button" onClick="GetContent(document.getElementById('cont').innerHTML)" value="      U p d a t e          "></input>


the problem was not html, but the quotes. i think so :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Video Tutorial help 2 51
REST call Failing 1 41
Scroll 5 news at a time using vticker 2 41
Woo-commerce gallery not working properly 12 42
When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question