Connecting Tech Pros Worldwide Help | Site Map

HELP: Javascript does not work in Firefox

Newbie
 
Join Date: Aug 2006
Posts: 4
#1: Aug 21 '06
Hi all, I'm new to this forum and I am hoping that there is someone here who can help me.

I have an ASP page that has javascript that works perfectly in IE, but not in Firefox. Can anybody tell me how to get it to work in FF. I can insert a browser identifier and redirect if the script has to change for FF only.

Basically, when a vistor goes to the page they are asked to click on images to chose the top 3 that they like - the images changes colour (another image) when they click on it and changes back if they click again. All of the validation (that is in the script as well) works, but the clicking on the images to change does not work. The code is below:
Expand|Select|Wrap|Line Numbers
  1.  
  2.         <script language="JavaScript">
  3. <!--
  4. function ButtonClick()
  5.             {
  6.                 if (document.survey.clickcount.value > 0)
  7.                 {
  8.                     // drag drop result
  9.                     var urlString = '';
  10.                     // check button result
  11.                     urlString = '';
  12.                     for (idx=0; idx < 17; idx++)
  13.                     {
  14.                         document.getElementById('v' + (idx+1)).value = document.getElementById('Img' + (idx+1)).myclick;
  15.                     }
  16.                 }
  17.                 else 
  18.                 {
  19.                     if (document.survey.q23a.value == '' && document.survey.q23b.value == '' && document.survey.q23c.value == '')
  20.                     {alert("Sorry, you must select or type at least one ");
  21.                     return false}
  22.                 }                
  23.             }
  24.  
  25.             function CheckClick(ctrl)
  26.             {
  27.  
  28.                 if (document.getElementById(ctrl.id).myclick == '2')
  29.                 {
  30.  
  31.             //New function start 18-Aug-2006            
  32.             var txtcount = 0;
  33.             if (document.survey.q23a.value !="")
  34.                 txtcount += 1;
  35.             if (document.survey.q23b.value !="")
  36.                 txtcount += 1;
  37.             if (document.survey.q23c.value !="")
  38.                 txtcount += 1;
  39.             if ((parseInt(document.survey.clickcount.value) + txtcount) >= 3)
  40.                 { alert("Sorry, you can only select or type three maximum ");
  41.                     return false;}
  42.             //New function end 18-Aug-2006
  43.                     //the following two lines are used to calculate number of clicks.
  44.                     if (document.survey.clickcount.value >= 3){
  45.                     //document.survey.clickcount.value=parseInt(document.survey.clickcount.value) + 1;
  46.                     alert("Sorry, you can only select or type three maximum ");}
  47.                     else{
  48.                     document.getElementById(ctrl.id).myclick = '1';
  49.                     document.getElementById(ctrl.id).src='images\\' + ctrl.id + '_on.gif';
  50.                     document.survey.clickcount.value=parseInt(document.survey.clickcount.value) + 1;}
  51.                 }
  52.                 else if (document.getElementById(ctrl.id).myclick == '1')
  53.                 {
  54.                     document.survey.clickcount.value=parseInt(document.survey.clickcount.value) - 1;
  55.                     document.getElementById(ctrl.id).myclick = '2';
  56.                     document.getElementById(ctrl.id).src='images\\' + ctrl.id + '_off.gif';
  57.                 }
  58.             }
  59.  
  60.             function NewFun(txtv)
  61.             {
  62.             var txtcount = 0;
  63.             if (document.survey.q23a.value !="")
  64.                 txtcount += 1;
  65.             if (document.survey.q23b.value !="")
  66.                 txtcount += 1;
  67.             if (document.survey.q23c.value !="")
  68.                 txtcount += 1;
  69.             if ((parseInt(document.survey.clickcount.value) + txtcount) > 3)
  70.                 { alert("Sorry, you can only select or type three maximum ");
  71.                     document.getElementById(txtv.id).value = "";
  72.                     return false;}
  73.             }
  74. //-->
  75. </script>
  76.  
  77. The elements on the page are (sorry, it is a lot):
  78.  
  79. <form name="survey" action="survey_23.asp" method="get">
  80. <input type="hidden" name="clickcount" value=0>
  81. <table width="700" height="423" border="0" align="center" cellpadding="0" cellspacing="0">
  82. <tr>
  83. <td width="700" height="371" valign="top" background="images/23_radio_bg.jpg">
  84.     <div id="DivCheckBox" style="Z-INDEX: 105; LEFT: 0px; WIDTH: 700px; POSITION: relative; TOP: 0px; HEIGHT: 72px">
  85. <table width="650" border="0" align="center" cellpadding="0" cellspacing="0">
  86. <tr>
  87. <td><div align="left"><img src="images/Img6_off.gif" width="69" height="35" hspace="5" border="0" align="center" id="Img6" onClick="CheckClick(this)" myclick="2"></div></td>
  88. <td><img src="images/Img3_off.gif" width="76" height="37" border="0" id="Img3" onClick="CheckClick(this)" myclick="2"></td>
  89. <td>&nbsp;</td>
  90. <td>&nbsp;</td>
  91. <td><img src="images/Img7_off.gif" width="68" height="34" border="0" align="right" id="Img7" onClick="CheckClick(this)" myclick="2"></td>
  92. <td><img src="images/Img10_off.gif" width="120" height="38" hspace="13" border="0" align="right" id="Img10" onClick="CheckClick(this)" myclick="2"></td>
  93. </tr>
  94. <tr>
  95. <td><img src="images/Img11_off.gif" width="79" height="43" border="0" id="Img11" onClick="CheckClick(this)" myclick="2"></td>
  96. <td>&nbsp;</td>
  97. <td><img src="images/Img2_off.gif" width="77" height="35" border="0" id="Img2" onClick="CheckClick(this)" myclick="2"></td>
  98. <td>&nbsp;</td>
  99. <td>&nbsp;</td>
  100. <td>&nbsp;</td>
  101. </tr>
  102. <tr>
  103. <td>&nbsp;</td>
  104. <td><img src="images/Img1_off.gif" width="75" height="35" vspace="10" border="0" id="Img1" onClick="CheckClick(this)" myclick="2"></td>
  105. <td>&nbsp;</td>
  106. <td>&nbsp;</td>
  107. <td valign="top"><img src="images/Img13_off.gif" width="81" height="37" border="0" id="Img13" onClick="CheckClick(this)" myclick="2"></td>
  108. <td>&nbsp;</td>
  109. </tr>
  110. <tr>
  111. <td><img src="images/Img15_off.gif" width="71" height="34" border="0" id="Img15" onClick="CheckClick(this)" myclick="2"></td>
  112. <td>&nbsp;</td>
  113. <td><img src="images/Img9_off.gif" width="68" height="34" border="0" id="Img9" onClick="CheckClick(this)" myclick="2"></td>
  114. <td>&nbsp;</td>
  115. <td>&nbsp;</td>
  116. <td><div align="right"><img src="images/Img8_off.gif" width="75" height="37" border="0" align="right" id="Img8" onClick="CheckClick(this)" myclick="2"><img src="images/Img5_off.gif" width="92" height="41" vspace="7" border="0" align="right" id="Img5" onClick="CheckClick(this)" myclick="2"></div></td>
  117. </tr>
  118. <tr>
  119. <td colspan="2"><img src="images/Img14_off.gif" width="123" height="37" border="0" id="Img14" onClick="CheckClick(this)" myclick="2"></td>
  120. <td colspan="3" valign="top"><img src="images/Img12_off.gif" width="103" height="34" hspace="23" vspace="5" border="0" align="left" id="Img12" onClick="CheckClick(this)" myclick="2"></td>
  121. <td align="right"><div align="right"><img src="images/Img17_off.gif" width="161" height="51" vspace="5" id="Img17" onClick="CheckClick(this)" myclick="2"></div></td>
  122. </tr>
  123. <tr>
  124. <td>&nbsp;</td>
  125. <td valign="bottom"><img src="images/Img16_off.gif" width="66" height="35" vspace="3" border="0" id="Img16" onClick="CheckClick(this)" myclick="2"></td>
  126. <td colspan="3" valign="top"><img src="images/Img4_off.gif" width="122" height="40" border="0" id="Img4" onClick="CheckClick(this)" myclick="2"></td>
  127. <td>&nbsp;</td>
  128. </tr>
  129. </table>                
  130. </div></td>
  131. </tr>
  132. <tr>
  133. <td height="29" valign="middle" bgcolor="#3399CC"><table width="100%" height="16" border="0" cellpadding="0" cellspacing="0">
  134. <tr>
  135. <td width="322"><img src="images/text_top_radio.gif" width="322" height="16"></td>
  136. <td width="120"><input name="q23a" type="text" class="input01" id="q23a" maxlength="99" value="" onKeyUp="return NewFun(this)"></td>
  137. <td width="3"><img src="images/spacer.gif" width="2" height="1" border="0" value="" onKeyUp="return NewFun(this)"></td>
  138. <td width="120"><input name="q23b" type="text" class="input01" id="q23b" maxlength="99" value="" onKeyUp="return NewFun(this)"></td>
  139. <td width="3"><img src="images/spacer.gif" width="2" height="1" border="0"></td>
  140. <td width="120"><input name="q23c" type="text" class="input01" id="q23c" maxlength="99" value="" onKeyUp="return NewFun(this)"></td>
  141. <td width="12"><img src="images/spacer.gif" width="12" height="1" border="0"></td>
  142. </tr>
  143. </table></td>
  144. </tr>
  145. <tr>
  146. <input type="hidden" name="RespID" value="<%=request("RespID")%>">
  147. <input type="hidden" name="tribe" value="<%=request("tribe")%>">
  148. <input type="hidden" name="v1">
  149. <input type="hidden" name="v2">
  150. <input type="hidden" name="v3">
  151. <input type="hidden" name="v4">
  152. <input type="hidden" name="v5">
  153. <input type="hidden" name="v6">
  154. <input type="hidden" name="v7">
  155. <input type="hidden" name="v8">
  156. <input type="hidden" name="v9">
  157. <input type="hidden" name="v10">
  158. <input type="hidden" name="v11">
  159. <input type="hidden" name="v12">
  160. <input type="hidden" name="v13">
  161. <input type="hidden" name="v14">
  162. <input type="hidden" name="v15">
  163. <input type="hidden" name="v16">
  164. <input type="hidden" name="v17">
  165. <td height="23"><table width="700" height="23" border="0" cellpadding="0" cellspacing="0">
  166. <tr>
  167. <% if request("bp")="" then %>
  168. <td width="56"><a href="survey_21.asp?bp=1&RespID=<%=request("RespID")%>&tribe=<%=request("tribe")%>" onMouseOver="MM_swapImage('backbut','','pbar/back02.gif',1)" onMouseOut="MM_swapImgRestore()"><img src="pbar/back01.gif" alt="BACK ONE QUESTION" name="backbut" width="56" height="23" border="0" id="backbut"></a></td>
  169. <% else %>
  170. <td width="56"><img src="pbar/spacer.gif" name="backbut" width="56" height="23" border="0" id="backbut"></td>
  171. <% end if %>
  172. <td width="588"><img src="pbar/pbar09.gif" width="588" height="23"></td>
  173. <td width="56"><input type="image" name="submit" value="NEXT" src="pbar/next01.gif" alt="NEXT QUESTION" width="56" height="23" border="0" id="submit" onMouseOver="MM_swapImage('submit','','pbar/next02.gif',1)" onMouseOut="MM_swapImgRestore()" onClick="return ButtonClick()"></td>
  174. </tr>
  175. </table></td>
  176. </tr>
  177. </table>
  178. </form>
  179.  
I would be grateful to anybody who can help me on this, as I have got out of my depth with this problem.

Thanks in advance.

Stewart
Falcon4's Avatar
Newbie
 
Join Date: Aug 2006
Posts: 3
#2: Aug 21 '06

re: HELP: Javascript does not work in Firefox


I didn't take all the time to see all that code (in theory it should be a very simple few-line script with a short array and a toggle if/else block), but as you know your own code best - plus being a bit of a JS n00b myself, I just offer one hint: Check the Tools menu for the JavaScript Console. It will tell you everything causing errors in your script. If you visit pages with ads on them, you'd probably do good to Clear them first, though... lots of sloppy coders out there =)
KUB365's Avatar
Administrator
 
Join Date: Jul 2005
Location: Portland, OR
Posts: 965
#3: Aug 22 '06

re: HELP: Javascript does not work in Firefox


Code tags help other members read the code a bit better. They makie it easier to for readers (potential helpers) sort out the code from the explanation part.

I went ahead and made the changes for you.

Here are some instructions on using code tags:
http://www.thescripts.com/forum/misc.php?do=bbcode#code
Newbie
 
Join Date: Aug 2006
Posts: 4
#4: Aug 22 '06

re: HELP: Javascript does not work in Firefox


Quote:

Originally Posted by Falcon4

I didn't take all the time to see all that code (in theory it should be a very simple few-line script with a short array and a toggle if/else block), but as you know your own code best - plus being a bit of a JS n00b myself, I just offer one hint: Check the Tools menu for the JavaScript Console. It will tell you everything causing errors in your script. If you visit pages with ads on them, you'd probably do good to Clear them first, though... lots of sloppy coders out there =)

Thanks for the advice and I do apologise for the large amount of code I have pasted. I did say that this was the first time I had done this and I really did not know of any other way - I do now.

Anyway, I have checked the Javascript Console and it shows no errors. It simply does not work in FF. To check if my console was working OK, I inserted an error and it showed. When I corrected it, no errors. I cannot understand, as according to all the JS sites on the web, it should work in FF.

Thanks for your advice anyway.
Newbie
 
Join Date: Aug 2006
Posts: 4
#5: Aug 22 '06

re: HELP: Javascript does not work in Firefox


Thank you KUB635 (administrator). I feel suitably put down now. I did say that this was the first time I had ever done this and I was expecting a little help rather than a condescending critique of my posting.

Rest assured that, in the future, I will follow your advice in posting. However, maybe you could show me what you mean this time.
KUB365's Avatar
Administrator
 
Join Date: Jul 2005
Location: Portland, OR
Posts: 965
#6: Aug 22 '06

re: HELP: Javascript does not work in Firefox


Papelotte,

Sorry for the way it came out in writing, i see my error now. It was just suppose to be an instruction for people who would end up posting replies to your question.

Here are the instructions to posting code:
http://www.thescripts.com/forum/misc.php?do=bbcode#code

If you have any questions, please feel free to PM me.

Thanks,
KUB
Newbie
 
Join Date: Aug 2006
Posts: 4
#7: Aug 23 '06

re: HELP: Javascript does not work in Firefox


Thanks KUB.
Newbie
 
Join Date: Nov 2006
Posts: 1
#8: Nov 3 '06

re: HELP: Javascript does not work in Firefox


I think that I'm experiencing the same problem. I have the following image and form element:

Expand|Select|Wrap|Line Numbers
  1. <img src="../../images/layout/noimage.jpg" id="pic16" name="pic16" style="height: 75px;">
  2. <input type="file" name="imfiles[16]" id="imfiles[16]" class="txtinput" size="10" onChange="imUpdate(16);">
  3.  
The javascript function changes the source of the image to whatever filename is selected in the input element:

Expand|Select|Wrap|Line Numbers
  1. function imUpdate(_which)
  2. {
  3.     _imID = "pic"+_which;
  4.     _elID="imfiles["+_which+"]";
  5.     _src=document.getElementById(_elID).value;
  6.     document.getElementById(_imID).src=_src;
  7. }
  8.  
  9.  
This works in IE, but not FF. I'm hoping this is just a matter of scripting, and not some sort of security problem. I use similar code on the back ends of several websites.
Reply