 The following is function i wrote to display the value of form elements set.however the if statements to determine wether a particular element is not empty and hence display the value attached to elements description goes on to display the elements description and an empty value which means the if statement is not evaluating correctly.i have tried several times to go through the code but i found no mistake.please help me to discover the error . any help is appreciated.
Code:
function showUserEntry(fieldRequired,fieldDescription){
// fieldRequired contains names of form elements
// fieldDescription contains description to be shown together with a form elements if the element contains a value
var alertMsg = "";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = document.symptoms.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex != -1 || obj.options[obj.selectedIndex].text != "")
{ alertMsg += fieldDescription[i] + " "+obj.options[obj.selectedIndex].value;
}
break;
case "select-multiple":
if (obj.selectedIndex != -1)
{
alertMsg +=" " +fieldDescription[i] + "\t"+obj.options[obj.selectedIndex].value;
}
break;
case "text":
if (obj.value != " " || obj.value != null)
{
alertMsg += fieldDescription[i] + "\t"+obj.value;
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
alertMsg +=" " + fieldDescription[i] +" "+obj[j].value;
}
}
}
}
}
var objDiv=document.getElementById('showvalue');
var objDiv.innerHTML+= alertMsg;
}
fieldRequired=Array("name","gender","state");
fieldRequired=Array("Username","Sex","User state");
showUserEntry(fieldRequired,fieldDescription);
|