I am new in Javascript. Need your help
I was working with an issue but could not figure it out. I need your help on this issue. I have a jsp file which shows Name field, Type drop down and Supervision Time Drop down. In original code when we select "Please select a Type" from the Drop down list and click on "Save" Button the pop up displays "Please select a Device Type" in the browser. But when we select other type from the drop down list it is not sowing anything as there was no alert message for other type from the list. I have show the same pop up message which is showing for the "Supervision Time" change now and that is "It may take... for Supervision Time" for the other type from the "Type" drop down list.
Now the issue occuring is when I put a else condition for the other type for "Type" drop down list and generate any message (for example: "You have selected other Type"), this alert message is generating in every field of this page. But I don't want this alert message in every field. I need it only for the other Type form the Tupe drop down list.
There is a validate() method in this JSP which generate these alert messages.
I am looking for your your suggession to avoid the alert message in every field expept for the other Type.
function validate()
{
if ( true == containsInvalidCharacter( 'Name', document.formSettings.name.value ) )
{
return false;
}
if ( null != document.formSettings.superTm )
{
var superTm = document.formSettings.superTm.value;
if ( true == document.formSettings.supervision.checked && ( -1 > superTm || superTm > 129600 ) )
{
alert( "Please select 1 <= Supervision Time <= 129600" );
return false;
}
var voldSuperTm = <%=oldSuperTm%>;
if ( voldSuperTm != superTm && -1 != voldSuperTm )
{
var scs = parseInt( voldSuperTm / 3 );
var hrs = parseInt( scs >= 3600 ? (scs / 3600) : 0 );
var mns = parseInt( scs >= 60 ? ((scs - (3600 * hrs)) / 60) : 0 );
scs -= ((3600 * hrs) + (60 * mns));
var msg = "";
if ( 0 != hrs )
{
msg += hrs + " hour(s) ";
}
if ( 0 != mns )
{
msg += mns + " minute(s) ";
}
if ( 0 != scs )
{
msg += scs + " second(s) ";
}
alert( "It may take " + msg + "for supervision time to change.");
}
}
if ( null != document.formSettings.type.options )
{
var selectedTypeOption = document.formSettings.type.selectedIndex;
var selectedTypeValue = document.formSettings.type.options[selectedTypeOption].value;
if ( selectedTypeValue == "none" )
{
alert( "Please select a device type" );
}
else
{
alert( "You have selected other Type" );
}
}
return true;
}