Anonymous578532

Hi, I'm attempting to write my first gadget. It's a deal that connects to a php server using ajax, grabs a "scripture passage for the day" kind of thing. Then, when you click the link, it will take you to a website that displays the scripture. All that is working fine. My problem comes when I decided to get fancy and add a settings page that would give the user a choice as to which version of scripture he wanted the text to be displayed in. The settings page has a simple drop down box with several choices. The user chooses a version and presses ok. At this point, the version should be written to the ini file as a user setting. However, when I open the ini file I do not see it in there. If I go back to my gadget and reopen my settings page, my version is still selected, so it's getting that info from somewhere. However, the hidden text field on my main gadget page that is supposed to hold the version is never populated. I have searched and searched and tried and tried. Maybe I'm just missing something. I'll post my code below.

Settings Page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Settings</title>
<style type="text/css">
body {

width:225px;
height:225px;
margin:0px;
}
</style>

<script type="text/javascript">
function wrench() {
var currentSetting = System.Gadget.Settings.read("trans");
if (currentSetting != "") {
document.versionForm.choice.selectedIndex = currentSetting;
}
}

System.Gadget.onSettingsClosing = SettingsClosing;
function SettingsClosing(event)
{
if (event.closeAction == event.Action.commit) {
trans = document.versionForm.choice.selectedIndex;
System.Gadget.Settings.write("trans", trans);
}

event.cancel = false;
}
</script>
</head>

<body onload="wrench()">
<p align="center" class="style3">Settings </p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><form id="versionForm" name="versionForm" method="get" action="">
<span class="style7">Select a Bible Version: </span>
<select name="choice" class="style6" id="choice">
<option value="KJV">KJV</option>
<option value="NIV">NIV</option>
<option value="NLT">NLT</option>
<option value="NAS">NAS</option>
<option value="NKJ">NKJ</option>
</select>
</form> </td>
</tr>
</table>
</body>
</html>


MAIN PAGE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!-- Standard style sheet links -->
<link rel="stylesheet" type="text/css" href="css.css" title="Standard" />
<title>Scripture</title>
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.passage.value=xmlHttp.responseText;

}

}

xmlHttp.open("GET","http://www.someurl.org/scripture.php",true);
xmlHttp.send(null);

}


function setContentText() {
var currentSetting = System.Gadget.Settings.read("trans");
if (currentSetting === "") {
document.myForm.version.value = "none";
} else {
document.myForm.version.value= currentSetting;
}
}

System.Gadget.settingsUI = "Settings.html";
System.Gadget.onSettingsClosed = SettingsClosed;

function SettingsClosed() {
trans = System.Gadget.Settings.read("trans");
setContentText();
}

//refreshes page every hour so that at midnight (or within an hour) the new day's passage is gotten
window.setInterval(refreshGadget, 360000);

function refreshGadget() {
location.href = location.href;
}
</script>

<style type="text/css">
<!--
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style></head>

<body onload="ajaxFunction(); setContentText();">
<table width="133" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="20" colspan="2" class="title"><div align="center">Today's Scripture </div></td>
<td width="12" height="20">&nbsp;</td>
</tr>
<tr>
<td width="40" height="13">&nbsp;</td>
<td height="13"><form id="myForm" name="myForm" method="get" action="http://www.biblegateway.com/bible">
<input name="passage" type="text" class="passage" id="passage" />
<input name="version" type="hidden" id="version" />
</form></td>
<td width="12" height="13">&nbsp;</td>
</tr>
<tr>
<td width="40">&nbsp;</td>
<td valign="top"><div align="center" class="text"><a href="javascriptBig Smileocument.myForm.submit();">Read Passage</a></div></td>
<td width="12">&nbsp;</td>
</tr>
</table>
</body>
</html>


Any help would be much appreciated. Thanks



Re: Sidebar Gadget Development settings not writing to ini

Jonathan Abbott

Apart from a typo in your main code, it looks okay to me:

function setContentText() {
var currentSetting = System.Gadget.Settings.readString("trans");
if (currentSetting === "") {

Before opening the settings.ini to check if the value is written, exit Sidebar which will force it to write the settings.




Re: Sidebar Gadget Development settings not writing to ini

ToddOs

Oddly enough, "===" is a valid javascript operator. I'm not really sure it's useful in this case, unless he's trying to prevent the case of 0 == "" = true. If that's the case, he probably ought to use readString() instead.



Re: Sidebar Gadget Development settings not writing to ini

Jonathan Abbott

Your right, although I forgot to change the read to a readString. I've corrected it now.