Java Script validation Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dumlee
Forum Commoner
Posts: 33
Joined: Mon Jun 30, 2008 12:06 am

Java Script validation Problem

Post by dumlee »

Java script Validation is not working.Please help.

Code in Html file:
=============
<select name="fldCountry" id="fldCountry" onchange="updateStates(this.form)">
</select>

fldCountry --> dropdown list Id

code in js file:
==========
if ( document.form.getElementById("fldCountry").value=="Country:" )
{
alert ( "Please fill in the 'Country' field." );

chk = false;
}

Populating the list:
==============
function resetForm(theForm)
{
/* reset makes */
theForm.fldCountry.options[0] = new Option("Country:", "");
for (var i=0; i<fldCountry.length; i++)
{
theForm.fldCountry.options[i+1] = new Option(fldCountry, fldCountry);
}
theForm.fldCountry.options[0].selected = true;
/* reset States */
theForm.fldStates.options[0] = new Option("State:", "");
theForm.fldStates.options[0].selected = true;
}

function updateStates(theForm) {
var fldCountry = theForm.fldCountry.options[theForm.fldCountry.options.selectedIndex].value;
var newStates = fldStates[fldCountry];
theForm.fldStates.options.length = 0;
theForm.fldStates.options[0] = new Option("State:", "");
for (var i=0; i<newStates.length; i++) {
theForm.fldStates.options[i+1] = new Option(newStates, newStates);
}
theForm.fldStates.options[0].selected = true;
}
Jaggeh
Forum Newbie
Posts: 16
Joined: Sat Jul 05, 2008 12:59 am
Location: Canada
Contact:

Re: Java Script validation Problem

Post by Jaggeh »

Have you checked W3Schools?
http://www.w3schools.com/

If no answers, try using a php code to do the same function, and it should work.
Post Reply