943,074 Members | Top Members by Rank

Ad:
Nov 18th, 2009
0

Script Not Working in Other Browser except IE

Expand Post »
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, 5 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
vishalonne is offline Offline
69 posts
since Jun 2009
Nov 18th, 2009
0
Re: Script Not Working in Other Browser except IE
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.
Reputation Points: 82
Solved Threads: 74
Posting Pro in Training
Graphix is offline Offline
400 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Select List/Menu Help
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: help.form page. no inner html





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC