Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 19th, 2004, 02:00 PM
Authorized User
 
Join Date: Jun 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
 
Old May 19th, 2004, 02:56 PM
Authorized User
 
Join Date: Jun 2003
Posts: 53
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi:

I figured out a solution.

I guess JavaScript doesn't like the function name to return the value. If I defined a variable and assigned the true/false value to it and returned that variable, the script works as intended.

Below is the new function.

Is it illegal, in JavaScript to use the function name to return the value?


Thanks,
JK

/////////////////////////////////////////////////////////////////
//
// This function is called to ensure a country was selected
//
/////////////////////////////////////////////////////////////////

function verifyCountrySelected()
{

    var objCountrySelected = document.getElementById('selectcountry');
    var blnCountrySelected = true;
    if (objCountrySelected.value == '')
    {
        alert('Please select a country.');
        blnCountrySelected = false;
    }

    objCountrySelected = null;
    return blnCountrySelected

}





Similar Threads
Thread Thread Starter Forum Replies Last Post
'Repeat' a stored procedure Shaneus BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 February 14th, 2008 06:49 AM
.js outside script problems Apocolypse2005 Javascript 1 July 25th, 2006 07:33 PM
no repeat selection! masgas MySQL 2 February 18th, 2006 01:17 PM
Sort a repeat region hendricksonet VBScript 0 August 11th, 2005 01:55 PM
JS Script help... Thomas82 Classic ASP Basics 2 April 29th, 2005 05:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.