Repeat use of a js script fails
Hi:
I'm stumped by what is happening. I have a country select box that I want to ensure a selection is made. The first entry has an empty string as a default value.
What I'm seeing is that if I click on the submit button, it works as expected.
If I click on it a second time, without making a selection in the select list, or even clicking on the select list, something fails and loads the 'action' page. The Javascript consoles complains that 'verifyCountrySelected' is not a function.
Using the Back button and clicking on the submit button a third time, operates properly.
A fourth, fails.
and so on.
This is a snippet of the select list
------------------------------------
<select name='country' id='selectcountry' class='copy'>
<option SELECTED value="">Select A Country</option>
<option value="AF">Afghanistan</option>
<option value="AL">Albania</option>
<option value="DZ">Algeria</option>
...
</select>
This is the javascript function
/////////////////////////////////////////////////////////////////
//
// This function is called to ensure a country was selected
//
/////////////////////////////////////////////////////////////////
function verifyCountrySelected()
{
var objCountrySelected = document.getElementById('selectcountry');
if (objCountrySelected.value == '')
{
verifyCountrySelected = false;
alert('Please select a country.');
}
else
{
verifyCountrySelected = true;
}
objCountrySelected = null;
return verifyCountrySelected;
}
I've tried using this as the onSubmit function for the form, and as the onClick function for the Submit button. In either case, it fails the same way.
Any ideas what might be happening here?
JK
|