Click to See Complete Forum and Search --> : Javascript question for duplicate entries


Rashar
12-08-2003, 10:10 AM
Looking to add script to the following code that will check for a duplicate entry, and alert the end user that a duplicate entry has been made. Thanks in advance.


<script language = "javascript">

function validateChoice()
{
// Get the source element.
var choice = event.srcElement;

// Valid numbers
var num = "0123456789";
event.returnValue = true;

/* Loop over Choices. If any Choice selected is not a number,
set the return value to false. */

for (var intLoop = 0; intLoop < choice.value.length; intLoop++)
if (-1 == num.indexOf(choice.value.charAt(intLoop)))
event.returnValue=false;

if (!event.returnValue) // Bad value
choice.className = "badValue"; // change colour of incorrect choice.

else
// Clear class to use default rendering.
choice.className="";
}
</SCRIPT>

jedioutcaster
01-05-2004, 11:46 PM
Why don't you try some more compact forms?


<script language = "javascript">

function validateChoice()
{
var choice = event.srcElement;

if(isNaN(choice.value) == true) {
choice.className = "badValue";
} else {
choice.className="";
}
</SCRIPT>

"isNaN" checks if the value is Not a Number.

By the way, what do you mean by checking for duplicate values?