Hey all,

I have the following HTML, adapted from a more complicated one I'm creating;

<HTML>
<HEAD>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
function setup(ans) {
  lit = ''
  if (ans == 'anim') {
    lit = '<br><br>How many legs?   '
    lit = lit + '<SELECT NAME="q2" ONCHANGE="print(document.quest.q2.value)">'
    lit = lit + '<OPTION VALUE="">- Please select -</OPTION>'
    lit = lit + '<OPTION VALUE="Cat">4</OPTION>'
    lit = lit + '<OPTION VALUE="Sparrow">2</OPTION>'
    lit = lit + '<OPTION VALUE="Snake">0</OPTION>'
    lit = lit + '</SELECT>'
  }
  if (ans == 'min') {
    lit = '<br><br>What colour?   '
    lit = lit + '<SELECT NAME="q2" ONCHANGE="print(document.quest.q2.value)">'
    lit = lit + '<OPTION VALUE="">- Please select -</OPTION>'
    lit = lit + '<OPTION VALUE="Emerald">Green</OPTION>'
    lit = lit + '<OPTION VALUE="Ruby">Red</OPTION>'
    lit = lit + '<OPTION VALUE="Sapphire">Blue</OPTION>'
    lit = lit + '</SELECT>'
  }
  if (ans == 'elem') {
    lit = '<br><br>What kind of element?   '
    lit = lit + '<SELECT NAME="q2" ONCHANGE="print(document.quest.q2.value)">'
    lit = lit + '<OPTION VALUE="">- Please select -</OPTION>'
    lit = lit + '<OPTION VALUE="Helium">Noble gas</OPTION>'
    lit = lit + '<OPTION VALUE="Fluorine">Halogen</OPTION>'
    lit = lit + '<OPTION VALUE="Lithium">Alkali metal</OPTION>'
    lit = lit + '</SELECT>'
  }
  document.getElementById('rep').innerHTML=lit
}

function print(statement) {
	document.getElementById('prt').innerHTML='<H3>You have chosen ' + statement
}

</SCRIPT>
</HEAD>
<BODY>

<FORM ACTION="#" NAME=quest>
What is it?   <SELECT NAME="q1" ONCHANGE="setup(document.quest.q1.value)">
<OPTION VALUE="">- Please select -</OPTION>
<OPTION VALUE="anim">Animal</OPTION>
<OPTION VALUE="min">Mineral</OPTION>
<OPTION VALUE="elem">Element</OPTION>
</SELECT>

<SPAN ID="rep"></SPAN>
<SPAN ID="prt"></SPAN>

</FORM>

</BODY>
</HTML>

The problem is that on refreshing the page, the "What is it?" drop-down box keeps the previously selected value. Is there any way to have the value in the box set to the default "-Please select-" text?

Thanks in advance guys!

sounds odd it should do that anyway but you could put in SELECTED

<OPTION VALUE="" SELECTED>- Please select -</OPTION>

Just tried it with the above code and my actual one I'm working on...still no luck!

What I have done for now is put in a "Reload Page" button within the 'print' function as follows;

<input type="button" value="Reload Page" onClick="window.location.reload()">

But I'd rather not do this, as I don't want to clutter the page any more than it needs to be. Any more ideas?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.