Forum Moderators: open

Message Too Old, No Replies

The variable seems right, but.

         

Rain_Lover

4:14 pm on Jan 28, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



Hi,

The following loop works:

<html>
<body>
<script type="text/javascript">
var i=0;
for (i=0;i<=5;i++)
{
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>


But the following doesn't:

<html>
<body>
<script type="text/javascript">
var i=0;
var x="i=0;i<=5;i++"
for (x)
{
document.write("The number is " + i);
document.write("<br />");
}
</script>
</body>
</html>


I'd just like to create a simple variable.
Please bear with me as I'm a newbie in JavaScript and let me know what I'm missing.

Many thanks in advance!
Rain Lover

Fotiman

4:35 pm on Jan 28, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



x contains a string, where as the for loop is looking for an expression. You may be able to use eval to evaluate the string, though I wonder why you would want to do it this way.

Rain_Lover

5:13 pm on Jan 29, 2011 (gmt 0)

10+ Year Member Top Contributors Of The Month



Let me provide my sample Google gadget:

<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
<ModulePrefs title="Sample Gadget" />
<UserPref name="order"
display_name="Results Order"
default_value="i = 0; i <= 5; i++" datatype="enum">
<EnumValue value="i = 0; i <= 5; i++" display_value="Ascending"/>
<EnumValue value="i = 5; i >= 0; i--" display_value="Descending"/>
</UserPref>
<Content type="html"><![CDATA[
<script type="text/javascript">
var i=0;
for (__UP_order__)
{
document.write("The number is " + i);
document.write("<br />");
}

</script>
]]></Content>
</Module>


It doesn't work because of the tags <> (they're not supported), and that's why I tried to define a variable for the EnumValue value.

Fotiman

5:51 pm on Jan 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ah, I'm not familiar with how Google gadgets work.