Jump to content

[SOLVED] javascript and firefox - not working well together


abazoskib

Recommended Posts

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>";

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.