abazoskib Posted August 18, 2009 Share Posted August 18, 2009 i've read that IE treats JS a lot nicer than FF, however this is rediculous. I cant even submit my form in firefox, focus a textfield, re populate a select box, and more. am i missing something? it all works fine in IE Quote Link to comment https://forums.phpfreaks.com/topic/170786-solved-javascript-and-firefox-not-working-well-together/ Share on other sites More sharing options...
corbin Posted August 18, 2009 Share Posted August 18, 2009 IE treats JS a lot nicer than FF? That's the first time I've ever heard that! Anyway, can we see code? Quote Link to comment https://forums.phpfreaks.com/topic/170786-solved-javascript-and-firefox-not-working-well-together/#findComment-900699 Share on other sites More sharing options...
abazoskib Posted August 18, 2009 Author Share Posted August 18, 2009 IE is totally more JS friendly. The code I am posting now WORKS in IE but DOES NOT WORK in FF: <script type="text/javascript">setFocus();</script> function setFocus() { document.getElementById("user_ai").focus(); } <input type="button" value="Login" onclick="checkForm();return false;" name="submit_ai" /> function checkForm() { if(document.getElementById('user_ai').value.length==0) alert("You must enter a username."); else if(document.getElementById('pass_ai').value.length==0) alert("You must enter a password."); else document.getElementById('log_ai').submit(); } echo "<script type=\"text/javascript\">"; echo "window.opener.document.getElementById('data_select').length = 0;"; while($row=mysql_fetch_assoc($resultSelection)) { $sel = $row['selection']; echo "var newOption = window.opener.document.createElement('<option value=\"$sel\">');"; echo "window.opener.document.getElementById('data_select').options.add(newOption);"; echo "newOption.innerText = \"$sel\";"; if(strcmp($sel,$value) == 0) { echo "var len = window.opener.document.getElementById('data_select').length;"; echo"window.opener.document.getElementById('data_select').selectedIndex = len-1;"; } } echo "</script>"; Quote Link to comment https://forums.phpfreaks.com/topic/170786-solved-javascript-and-firefox-not-working-well-together/#findComment-900712 Share on other sites More sharing options...
haku Posted August 18, 2009 Share Posted August 18, 2009 FF deals with javascript much better than IE. The problem isn't with IE, it's with your code! You have the function setFocus() and checkForm() not even in script tags. Then later on you are echoing another script, but it's not even in php tags. The only reason IE is parsing it, is because IE is screwed, and will parse garbage sometimes. Quote Link to comment https://forums.phpfreaks.com/topic/170786-solved-javascript-and-firefox-not-working-well-together/#findComment-900732 Share on other sites More sharing options...
abazoskib Posted August 18, 2009 Author Share Posted August 18, 2009 I'm sorry I should have said this earlier. I just posted the bits and pieces that dont work. Everything is in correct context here. Quote Link to comment https://forums.phpfreaks.com/topic/170786-solved-javascript-and-firefox-not-working-well-together/#findComment-900844 Share on other sites More sharing options...
abazoskib Posted August 18, 2009 Author Share Posted August 18, 2009 Fixed everything except for my dynamic select options. Here's the code(which now for some reason after editing does not return an error message) that doesn't work. if($type == "xx") { if($insert) { $queryxx = "query here"; $resultxx = mysql_query($queryxx); echo "<script type=\"text/javascript\">"; echo "window.opener.document.getElementById('xx').length = 0;"; while($row=mysql_fetch_assoc($resultxx)) { $id = $row['xx_id']; $name = $row['name']; $code = $row['code']; $text = $code." - ".$name; $splice = $id."-".$code; echo "var newOption = window.opener.document.createElement(\"option\");"; echo "newOption.setAttribute(\"value\",\"$splice\");"; echo "window.opener.document.getElementById('xx').options.add(newOption);"; echo "newOption.innerText = \"$text\";"; if(strcmp($code,$value) == 0) { echo "var len = window.opener.document.getElementById('xx').length;"; echo"window.opener.document.getElementById('xx').selectedIndex = len-1;"; } } echo "</script>"; Quote Link to comment https://forums.phpfreaks.com/topic/170786-solved-javascript-and-firefox-not-working-well-together/#findComment-900993 Share on other sites More sharing options...
KevinM1 Posted August 18, 2009 Share Posted August 18, 2009 Can you post just the JavaScript that's in your source code? Quote Link to comment https://forums.phpfreaks.com/topic/170786-solved-javascript-and-firefox-not-working-well-together/#findComment-901024 Share on other sites More sharing options...
abazoskib Posted August 18, 2009 Author Share Posted August 18, 2009 That last post I made is the source code. Iused Javascript inline with PHP to create dynamically loading drop down boxes. Im not very good with Ajax, so I improvised. Quote Link to comment https://forums.phpfreaks.com/topic/170786-solved-javascript-and-firefox-not-working-well-together/#findComment-901031 Share on other sites More sharing options...
KevinM1 Posted August 18, 2009 Share Posted August 18, 2009 That last post I made is the source code. Iused Javascript inline with PHP to create dynamically loading drop down boxes. Im not very good with Ajax, so I improvised. Yes, but I'd like to see what is actually in the source, sans PHP. I want to see if the JS is actually being written correctly by the PHP. Quote Link to comment https://forums.phpfreaks.com/topic/170786-solved-javascript-and-firefox-not-working-well-together/#findComment-901088 Share on other sites More sharing options...
abazoskib Posted August 18, 2009 Author Share Posted August 18, 2009 <script type="text/javascript"> window.opener.document.getElementById('ESP').length = 0; var newOption = window.opener.document.createElement("option"); newOption.setAttribute("value","1-PS"); window.opener.document.getElementById('ESP').options.add(newOption); newOption.innerText = "PS - PureSend"; var newOption = window.opener.document.createElement("option"); newOption.setAttribute("value","2-BH"); window.opener.document.getElementById('ESP').options.add(newOption); newOption.innerText = "BH - BlueHornet"; var newOption = window.opener.document.createElement("option"); newOption.setAttribute("value","3-OM"); window.opener.document.getElementById('ESP').options.add(newOption); newOption.innerText = "OM - Options Media"; var newOption = window.opener.document.createElement("option"); newOption.setAttribute("value","41-FT"); window.opener.document.getElementById('ESP').options.add(newOption); newOption.innerText = "FT - fool r us"; var len = window.opener.document.getElementById('ESP').length; window.opener.document.getElementById('ESP').selectedIndex = len-1; var newOption = window.opener.document.createElement("option"); newOption.setAttribute("value","40-WW"); window.opener.document.getElementById('ESP').options.add(newOption); newOption.innerText = "WW - wicked witch"; var newOption = window.opener.document.createElement("option"); newOption.setAttribute("value","39-PB"); window.opener.document.getElementById('ESP').options.add(newOption); newOption.innerText = "PB - pirate boat"; var newOption = window.opener.document.createElement("option"); newOption.setAttribute("value","38-MP"); window.opener.document.getElementById('ESP').options.add(newOption); newOption.innerText = "MP - monkey poo"; var newOption = window.opener.document.createElement("option"); newOption.setAttribute("value","37-CP"); window.opener.document.getElementById('ESP').options.add(newOption); newOption.innerText = "CP - cow poo"; </script> <tr> <td> <span style="color:red; font-weight: bolder; font-size: 10px;">Successfully Added New Item</span></td></tr><tr> Quote Link to comment https://forums.phpfreaks.com/topic/170786-solved-javascript-and-firefox-not-working-well-together/#findComment-901125 Share on other sites More sharing options...
KevinM1 Posted August 18, 2009 Share Posted August 18, 2009 Okay, good. And what doesn't work, specifically? Are the options not being created? Do they not have the correct values? EDIT: Try - window.opener.document.getElementById('ESP').options.add(newOption, null); Quote Link to comment https://forums.phpfreaks.com/topic/170786-solved-javascript-and-firefox-not-working-well-together/#findComment-901136 Share on other sites More sharing options...
abazoskib Posted August 18, 2009 Author Share Posted August 18, 2009 The result is that the dropdown list contains no text. I think I have a hunch, but maybe I should be using innerHTML ? Quote Link to comment https://forums.phpfreaks.com/topic/170786-solved-javascript-and-firefox-not-working-well-together/#findComment-901144 Share on other sites More sharing options...
abazoskib Posted August 18, 2009 Author Share Posted August 18, 2009 aha! i was right, but couldnt have done it without all your help everyone. thanks! Makes sense, since a select box is an HTML element not a space for text. Quote Link to comment https://forums.phpfreaks.com/topic/170786-solved-javascript-and-firefox-not-working-well-together/#findComment-901229 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.