views:

147

answers:

2

I am trying to embed a 3rd party chart (Twist) into an HTML page. Also on the HTML page, I am using a text input to allow for a user to dynamically enter new parameters to be sent to Twist.

In javascript, I am attempting to append the text input to the end of the call to the external chart. I cannot, however, figure out how to have the returned JavaScript render in my page.

Let me be more specific... the instructions for embedding the chart are to put a tag into the html. So it would be like below, where 'paramValue' is the value passed to the 3rd party.

<script src='http://twist.flaptor.com/embed?size=large&amp;gram=paramValue&amp;span=168&amp;'&gt;&lt;/script&gt;

This works fine, but it is hard-coded to search for 'paramValue'. The script returns more javascript that gets embedded into my page and renders a chart. I am trying to make this dynamic by replacing 'paramValue' with the text input from a user. However, I cannot figure out how to send that value and also have the results rendered properly.

+1  A: 

Looking at that javascript, it uses document.write(). document.write() writes to the document during loading, but if invoked after the page has been loaded doesn't work well.

In short, you can't do it by just changing paramValue and adding a new script tag.

Try to see if Twist has something for dynamic content.

Sinan Taifour
A: 

On behalf of Stu42:

<script type="text/javascript" language="javascript">
 var paramValue = GetParamValue();
 var url = "<div";
 url += '>'
 url += "<script src='http://twist.flaptor.com/embed?size=large&amp;span=168&amp;gram=";
 url += paramValue;
 url += "'";
 url += '>';
 url += "</script>";
 url += "</div";
 url += '>';
 document.write(url) ;
</script>
John Smithers