By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

Function written in javascript is not working in internet explorer

P: 34
Hello guys
i have one function which converts the ip/netmask into networkid/netmask and also it shows the message to user that his ip is changed to network id. but that function is working in mozilla perfectly but not in IE.

To check where is the fault i have written so many alert() but sometimes these are working.
Please someone read my code and tell me why its not working.
i am also sending you the function validateIPandNetMask()
my alert statement is commented so that one can understand my code
Expand|Select|Wrap|Line Numbers
  1. var enteredip;
  2.     function validateIPandNetMask()
  3.     {
  4.  
  5.        enteredip=document.addform.ipaddress.value
  6.        firstvalue=document.addform.ipaddress.value;
  7.        //alert("fstvalue="+firstvalue)
  8.        ipnetmaskarr=firstvalue.split("/");
  9.        ip=ipnetmaskarr[0];
  10.        nm=ipnetmaskarr[1];
  11.        //alert("ipnetmask0="+ipnetmaskarr[0]+"ipnetmask1="+ipnetmaskarr[1]);
  12.        if(ipnetmaskarr[1]==null)
  13.        {
  14.             if(validateIPAddress(ipnetmaskarr[0]))
  15.             {
  16.                if(isBrowserIE())
  17.                 {
  18.                     window.returnvalue=addform.userid.value+'/'+addform.ipaddress.value;
  19.                 }
  20.                 else
  21.                 {
  22.                     opener.document.viewform.userid.value=document.addform.userid.value;
  23.                     opener.document.viewform.ipaddress.value = firstvalue;
  24.                     opener.document.viewform.mode.value = "<%=FWBMModes.ADD%>";
  25.                     opener.document.viewform.submit();
  26.                 }
  27.                 self.close();
  28.             } 
  29.               else
  30.             {
  31.                 alert("Enter a valid IP Address before proceeding");
  32.                 addform.ipaddress.focus();
  33.                 return false;
  34.             }
  35.        }
  36.         else
  37.         {
  38.         //alert("ip= "+ip+" nm="+nm);
  39.             if(validateIPAddress(ipnetmaskarr[0]))
  40.             {
  41.                 if(validateIPNetmask(ipnetmaskarr[1]))
  42.                 {
  43.                     if(isBrowserIE())
  44.                     {
  45.                         window.returnvalue=addform.userid.value+'/'+addform.ipaddress.value;
  46.                     }
  47.                     else
  48.                     {
  49.  
  50.                      //alert("ipnetmask0="+ipnetmaskarr[0]+"ipnetmask1="+ipnetmaskarr[1]);
  51.                         //alert("ippppp= "+ip+" nm="+nm);//In internet explorer this line is executed sometime
  52.                            var networkarr=new Array(4)//not  ok
  53.                            //alert("ip= "+ip+" nm="+nm); //This alert is not working always
  54.                         iparr=ipnetmaskarr[0].split(".");//from this nothing is happening
  55.                         //alert("iparr="+iparr);
  56.                         nmarr=ipnetmaskarr[1].split(".");
  57.                         for(i=0;i<iparr.length;i++)
  58.                         {
  59.                             networkarr[i]=iparr[i]&nmarr[i];
  60.                         }
  61.                         networkid=networkarr.join(".")
  62.                         ipnmaddr=networkid+'/'+ipnetmaskarr[1] 
  63.                         //document.getElementById('ipaddress').value=ipnmaddr;
  64.                         document.addform.ipaddress.value=ipnmaddr;
  65.                         if(firstvalue==ipnmaddr)
  66.                         {
  67.                             opener.document.viewform.userid.value=document.addform.userid.value;
  68.                             opener.document.viewform.ipaddress.value =document.addform.ipaddress.value
  69.                             opener.document.viewform.mode.value = "<%=FWBMModes.ADD%>";
  70.                             opener.document.viewform.submit();
  71.                             self.close();
  72.                         }
  73.                         else
  74.                         {
  75.                             // The networkid is displayed dynamically
  76.                                 document.fgColor="red"
  77.                                 var tbl = document.getElementById('tblgui');
  78.                                 var lastRow = tbl.rows.length;
  79.                                 if (lastRow >= 1) 
  80.                                 {
  81.                                     tbl.deleteRow(lastRow - 1);
  82.                                     var row = tbl.insertRow(lastRow-1);
  83.                                     text = document.createTextNode("The IP address("+firstvalue+") is changed to networkid");
  84.                                     row.appendChild(text)
  85.                                     document.addform.ignore.disabled=false;
  86.                                     flag=false;
  87.                                     return false;
  88.                                 }
  89.                                 else
  90.                                 {
  91.                                     var row = tbl.insertRow(lastRow);
  92.                                     text = document.createTextNode("The IP address("+firstvalue+") is changed to networkid");
  93.                                     row.appendChild(text)
  94.                                     document.addform.ignore.disabled=false;
  95.                                     flag=false;
  96.                                     return false;
  97.                                 }        
  98.                         }
  99.                     }
  100.  
  101.                  }
  102.                 else
  103.                 {
  104.                 alert("Enter a valid NetMask before proceeding");
  105.                 addform.ipaddress.focus();
  106.                     return false;
  107.                 }
  108.         }
  109.         else
  110.         {
  111.             alert("Enter a valid IP Address before proceeding");
  112.             addform.ipaddress.focus();
  113.             return false;
  114.         }
  115.       }
  116.     }
Oct 5 '07 #1
Share this Question
Share on Google+
3 Replies


dmjpro
100+
P: 2,476
What do you mean by "sometimes these are working." ?

Kind regards,
Debasis Jana
Oct 5 '07 #2

acoder
Expert Mod 15k+
P: 16,027
BibhuAshish, welcome to TSDN!

Please use code tags when posting code:

[CODE=javascript]
JavaScript code here...
[/code]
Oct 5 '07 #3

pbmods
Expert 5K+
P: 5,821
Heya, Bibhu.

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Oct 5 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.