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

script working in IE but not Firefox

P: n/a
I am trying to get a portion of javascript to work in Firefox that works perfectly in I.E.

In this first section of code, I have a drop down box that when the value is changed to 29 (Other), it should show an input box. When the value does not equal 29, it should hide the box (for experiment purpose, I don't have it hiding upon load, but will make that happen when the script is fixed).

I can't get this to work in FireFox.

Expand|Select|Wrap|Line Numbers
  1.   <html>  
  2.   <head>  
  3.   <title>getElementById example</title>  
  4.   <script language="JavaScript"> 
  5.     function JTOther_Toggle(itemID){
  6.       var othval = 29;
  7.       var JTitle = document.getElementById("JTTitle1");
  8.       var JInput = document.getElementById("JTInput1");
  9.       if (othval == this.sysForm.JobFunctionId.value)
  10.          {JTitle.style.display = 'inline'; 
  11.           JInput.style.display = 'inline';}  
  12.       else
  13.          {JTitle.style.display = 'none'; 
  14.           JInput.style.display = 'none';} } 
  15.   </script>
  16.   </head>  
  17.   <body>  
  18.   <form action="user_action.htm" method="POST" name="sysForm" id="sysForm" onsubmit="return Validate(this.form)">
  19.     <div id="JobTitleDD">
  20.       Job Title:  
  21.       <select name="JobFunctionId" id="JobFunctionId" size="1" onchange="JTOther_Toggle(this.value);">
  22.         <option value="0" selected="YES">No Title Selected</option>
  23.         <option value="25">Director</option>
  24.         <option value="29">Other</option>
  25.         <option value="3">President</option>
  26.       </select>
  27.     </div>
  28.     <div id="JTTitle1">Other Title:</div>
  29.     <div id="JTInput1">
  30.       <input type="Text" name="JTOther" value="" size="30" maxlength="75" id="JTOther">
  31.     </div>
  32.   </form>
  33. </body>  
  34. </html>  
  35.  
So while experimenting, I found the below sample which is very similar to the one above. It works just fine in both browsers.

Expand|Select|Wrap|Line Numbers
  1.   <html>  
  2.   <head>  
  3.   <title>getElementById example</title>  
  4.   <script type="text/javascript">  
  5.     function changeShow(myvalue) {  
  6.      var elem = document.getElementById("para1");  
  7.      elem.style.display = 'inline'; }  
  8.   function changeHide(myvalue) {  
  9.    var elem = document.getElementById("para1");  
  10.    elem.style.display = 'none'; }  
  11.   </script>  
  12.   </head>  
  13.   <body>  
  14.  
  15.   <p id="para1">Display some text here</p>
  16.   <br><br>  
  17.   <button onclick="changeShow('show');">Show</button>  
  18.   <button onclick="changeHide('hide');">Hide</button>  
  19. </body>  
  20. </html>  
  21.  
  22.  
Can someone help me understand what I am missing to get the first option to work in FireFox?

THANKS!
Nov 18 '10 #1
Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
the second code is somewhat problematic.

- would you put that into a <form>, you’d get a form submission
- you don’t use the parameters passed.

the first code has a similar problem, you pass the currently selected value, but you never use that.

try
Expand|Select|Wrap|Line Numbers
  1. if (29 == itemID) {
Nov 19 '10 #2

JKing
Expert 100+
P: 1,206
Misread what has already been said, making my post irrelevant. Go with dormlich's suggestion.
Nov 19 '10 #3

Post your reply

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