Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
if statement not evaluating correctly
Old 02-25-2010, 03:23 AM if statement not evaluating correctly
Skilled Talker

Posts: 54
Trades: 0
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);
kani alavi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to if statement not evaluating correctly
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.33283 seconds with 12 queries