2 messages in com.googlegroups.google-gadgets-apiJavascript in gadget isn't working
FromSent OnAttachments
Syriven22 Jul 2006 00:36 
Syriven22 Jul 2006 00:41 
Subject:Javascript in gadget isn't working
From:Syriven (Syri@gmail.com)
Date:07/22/2006 12:36:00 AM
List:com.googlegroups.google-gadgets-api

I've just started working with gadgets, and I am trying to develop an xml gadget. My javascript inside the <script> tags doesn't seem to work, though. I know it's something in my code, and not me adding it wrong or anything.

All of the plain html works fine, and javascript actions that are attatced to html elements (like <span onClick='alert("hello")'>) work fine, but nothing seems to be happening between the <script> tags--I can't define or call functions there.

I would really appreciate it if someone could look at my code and tell me why it's not working...

Obviously, you don't need to read all of the stuff between the <script> tags. It doesn't matter what I have in there, i think.

<?xml version="1.0" encoding="UTF-8" ?> <Module> <ModulePrefs title="My first gadget" /> <Content type="html"> <![CDATA[ <script type="text/javascript">

var http_request = false; function makeRequest(url,getOrSet) { http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } if (getOrSet=="get") { http_request.onreadystatechange=getInfo; } else if (getOrSet=="set") { http_request.onreadystatechange=setInfo; } else if (getOrSet=="getOptions") { http_request.onreadystatechange=getOptions; } else { http_request.onreadystatechange=setOptions; } http_request.open('GET', url, true); http_request.send(null); } function getInfo() { if (http_request.readyState == 4) { if (http_request.status == 200) { var rawInfo=http_request.responseText; var info = new Array(); info=rawInfo.split("RETURNED VALUE:0:4:P:"); changeBlob(info[1]); } else { alert('There was a problem with the request.'); } } } function refreshBlobOnly() { changeElement("loading","(Loading...)");

makeRequest("http://www.putphrase.net/getBlob.php","get"); } function changeBlob(text) { text=breakLongWords(text); changeElement("blob",text); changeElement("loading","<br>"); } function changeElement(id,text) { var item; item=getElementById(id); item.innerHTML=text; } function breakLongWords(string) { var wordList=string.split(" "); var newString=""; var count1; for (count1=0;count1<wordList.length;count1++) { if (wordList[count1].length>20) { var count2; for (count2=0;count2<wordList[count1].length;count2++) { if (count2%20==0 & count2!=0) { newString+="<font color=#0000FF>-</font>"; } newString+=wordList[count1].charAt(count2); } } else { newString+=wordList[count1]; } newString+=" "; } return newString; } </script> <a id="loading"></a><br><a id="blob"></a><br> <span style="cursor: pointer; text-decoration: underline" onclick="changeElement('blob','testing again')">Skip</span><br> ]]> </Content> </Module>