Script Not Working in Other Browser except IE

Reply

Join Date: Jun 2009
Posts: 40
Reputation: vishalonne is an unknown quantity at this point 
Solved Threads: 0
vishalonne vishalonne is offline Offline
Light Poster

Script Not Working in Other Browser except IE

 
0
  #1
Nov 18th, 2009
Dear All Experts

I wrote a simple code in javascript and it is working fine with IE but when I open the page in FireFox or in Google Crome it is not working as I expect. Actually I am enabling and disabling the combo box on the on change event of radio button.

Please check the code attached here. And visit my site for output
www.crispwerx.com/catasset

Thanx to all viewer and helper
Attached Files
File Type: php index.php (2.5 KB, 1 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 145
Reputation: Graphix is an unknown quantity at this point 
Solved Threads: 32
Graphix's Avatar
Graphix Graphix is offline Offline
Junior Poster
 
0
  #2
Nov 18th, 2009
Hi, there are a few things wrong with your code, it seems like you dont understand the difference between a name and an id. An id is unique, a name is not. You can not retrieve a name with getElementById(). The following code will work in all browsers:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2. mysql_connect("localhost", "crispwer_vishal", "vishal@123") or die(mysql_error());
  3. mysql_select_db("crispwer_navy") or die(mysql_error());
  4.  
  5. $query = "SELECT * FROM depatment";
  6. $result = mysql_query($query);
  7. ?>
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  12. <title>Login Form</title>
  13. <link href="loginmodule.css" rel="stylesheet" type="text/css" />
  14. <script type="text/javascript">
  15. // This function sets the usertype at disabled
  16. function sle()
  17. {
  18. document.getElementById("userDept").disabled=true;
  19. }
  20. // This function decides whether the usertype should be enabled
  21. function ss(niit)
  22. {
  23. var s = niit;
  24. switch(s)
  25. {
  26. case '1':
  27. document.getElementById("userDept").disabled=true;
  28. break
  29. case '2':
  30. document.getElementById("userDept").disabled=true;
  31. break
  32. case '3':
  33. document.getElementById("userDept").disabled=false;
  34. break
  35. default:
  36. document.write("ERROR")
  37. }
  38. }
  39. </script>
  40. </head>
  41. <body onLoad="sle()">
  42. <p>&nbsp;</p>
  43. <form id="loginForm" name="loginForm" method="post" action="userchek.php">
  44. <hr />
  45. <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
  46. <tr>
  47. <td colspan="3">
  48. <input name="loginType" type="radio" id="1" onclick="ss(this.id); return true;';" value="administrator" />
  49. Administrator|
  50. <input name="loginType" type="radio" id="2" onclick="ss(this.id); return true;" value="storekeeper" />
  51. Store Keeper |
  52. <input name="loginType" type="radio" id="3" onclick="ss(this.id); return true;" value="user" />
  53. User</td>
  54. </tr>
  55. </tr>
  56. <tr>
  57. <td colspan="3">User Department
  58. <select id="userDept" name="userDept">
  59. <option>Select</option>
  60. <?php while($row = mysql_fetch_array($result))
  61. {
  62. echo "<option>$row[Dept_Name]</option>";
  63. }?>
  64. </select>
  65. </td>
  66. </tr>
  67. <tr>
  68. <td width="111"><b>Login</b><td colspan="2"><input name="login" type="text" class="textfield" id="login" /></td>
  69. </tr>
  70. <tr>
  71. <td><b>Password</b></td>
  72. <td colspan="2"><br />
  73. <input name="password" type="password" class="textfield" id="password" />
  74. <br /></td>
  75. </tr>
  76. <tr>
  77. <td><input type="submit" name="Submit" onclick="newwindow();" value=" LOGIN " /></td>
  78. <td width="97"><input type="submit" name="Submit2" value="Forgot Password" /></td>
  79. <td width="80"><input type="submit" name="Submit3" value="New User" /></td>
  80. </tr>
  81. </table>
  82. <hr />
  83. </form>
  84. </body>
  85. </html>
Please note that the names of the selects/checkboxes have changed, so use the following names to retrieve the values:

- $_POST['loginType'] // Admin, storekeeper or user
- $_POST['userDept'] // User department
- $_POST['login'] // Username
- $_POST['password'] // Password

~G
Last edited by Graphix; Nov 18th, 2009 at 11:53 am.
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 553 | Replies: 1
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC