Reply
PHP echo JavaScript.. FireFox chokes?
Old 12-14-2007, 03:28 AM PHP echo JavaScript.. FireFox chokes?
Novice Talker

Posts: 8
Hi Guys
I apologize for my stupidity... it is very late where I am and I'm not seeing what could be obvious. I have a php script outputting some javascript and it runs properly on IE but not FireFox.. Any Ideas?

Code:

PHP Code:
if ($Success != 1){
 echo 
'
 <form name="errorform" method="post" action="index.php">
 <input type="hidden" name="error" value="yes">
 </form>
 <script language="javascript">
 document.errorform.submit();
 </script>
 exit();
 '
;

In IE, this code uses "index.php" as the action for the very simple form "errorform". it posts to the index and I am able to $_REQUEST the data.

In FireFox, I can view the source of the file and it contains all of the code (minus the echo, of course), yet it only prints "exit();" on the page...

Again, I'm exhausted, please be kind!
AMdeveloper is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 12-14-2007, 03:30 AM Re: PHP echo JavaScript.. FireFox chokes?
Novice Talker

Posts: 8
Oh.... Oh good lord.

Upon review of the thread I *just* posted, I found my mistake...
my exit() is inside my echo...

Sorry guys!

Bedtime for me...
AMdeveloper is offline
Reply With Quote
View Public Profile
 
Old 12-14-2007, 03:31 AM Re: PHP echo JavaScript.. FireFox chokes?
Novice Talker

Posts: 8
hmm.. still doesn't work... issue reopened!
AMdeveloper is offline
Reply With Quote
View Public Profile
 
Old 12-14-2007, 04:11 AM Re: PHP echo JavaScript.. FireFox chokes?
evans123's Avatar
Ultra Talker

Posts: 272
Heres some of my code for my website might help you a little:

Function:
PHP Code:
function Uncheck()
    {
 <?php 
 $sql 
mysql_query("SELECT * FROM `manager__players` WHERE `team_id` = '" $_SESSION['team_id'] . "' && `position` = 'GK'");
  while(
$row mysql_fetch_array($sql))
  {
  echo 
"if(document.myform.player_" $row['player_id'] . ".checked == false) {";
   
$dis mysql_query("SELECT * FROM `manager__players` WHERE `team_id` = '" $_SESSION['team_id'] . "' && `position` = 'GK' && `player_id` != '" $row['player_id'] . "'");
   while(
$row2 mysql_fetch_array($dis))
   {
  echo 
"document.myform.player_" $row2['player_id'] . ".disabled = false; ";
  } 
  echo 
"}";
}
  
?>
  document.write('hey');
  }
</script>
And The Checkbox Upon Check:

PHP Code:
<?php
                  
            $pos 
= array("GK");
            echo 
"<tr><td><strong>Goalkeeper's</strong></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
foreach (
$pos as $key => $val) {
                  
// substr($row['first_name'], 0, 1)
 
$sql mysql_query("SELECT * FROM `manager__******` WHERE `team_id` = '" $_SESSION['team_id'] . "' && `position` = '" $val "' ORDER BY `overall_rating` DESC");
  while(
$row mysql_fetch_array($sql))
  { 
  
$pic substr($row['overall_rating'], 01);
  if(
$row['overall_rating'] == 100)
  {
  
$pic 10;
  }
                  echo 
"<tr>
                   <td align='center'><input type='checkbox' name='player_" 
$row['player_id'] . "' value='checkbox' onClick='javscript:if(this.checked.false) { Uncheck(); } if(this.checked=true) { Check(); }' /></td>
                    <td align='center'>" 
$row['position'] . "</td>
                    <td>" 
$row['first_name'] . " " $row['second_name'] . " (" $row['overall_rating'] . ")</td>
                    <td align='center'>" 
$row['age'] . "</td>
                    <td align='center'></td>
                    <td align='center'></td>
                    <td align='center'></td>
                    <td align='center'><span TITLE='" 
$row['overall_rating'] . "/100'><img src='images/ratings/$pic.gif' alt='Rank Image' width='43' height='10'/></span></td>
                  </tr>"
;
                  }
}
                  
?>
__________________
SoldierExteme.com - Free MMORPG - sign-up today!
Backthebulls.com - Free online games (mad_willsy's)
Msnextra.co.uk - Msn Items
evans123 is offline
Reply With Quote
View Public Profile
 
Old 12-14-2007, 04:13 AM Re: PHP echo JavaScript.. FireFox chokes?
evans123's Avatar
Ultra Talker

Posts: 272
ps get rid of the double quotes around javascript: here ya go try this:

PHP Code:
<?php
if ($Success != 1){
 echo 
"
 <form name='errorform' method='post' action='index.php'>
 <input type='hidden' name='error' value='yes'>
 </form>
 <script language='javascript'>
 document.errorform.submit();
 </script>
  "
;
exit();

?>
</span></span>
__________________
SoldierExteme.com - Free MMORPG - sign-up today!
Backthebulls.com - Free online games (mad_willsy's)
Msnextra.co.uk - Msn Items
evans123 is offline
Reply With Quote
View Public Profile
 
Old 12-14-2007, 09:49 AM Re: PHP echo JavaScript.. FireFox chokes?
chrishirst's Avatar
Super Moderator

Posts: 15,326
Location: Blackpool. UK
<script type="text/javascript">
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-14-2007, 11:33 AM Re: PHP echo JavaScript.. FireFox chokes?
Novice Talker

Posts: 8
Thanks for the replies guys
I have gotten some sleep and tried your suggestions, but still, IE works as expected and FireFox doesn't budge..

Any ideas?
AMdeveloper is offline
Reply With Quote
View Public Profile
 
Old 12-14-2007, 12:34 PM Re: PHP echo JavaScript.. FireFox chokes?
Novice Talker

Posts: 8
I found the solution - for anyone who is interested.
The problem is a FireFox timing issue, and this thread should have been started in the Javascript forum

I have solved the problem by setting a very short delay in the script execution, allowing FireFox to catch up...


SOLUTION:

PHP Code:
if ($Success != 1){
 echo 
'
 <form name="errorform" method="post" action="index.php">
   <input type="hidden" name="error" value="yes" />
 </form>
 
 <script type="text/javascript" language="javascript">
   setTimeout("document.errorform.submit()",50);
 </script>
 '
;
 exit();

Thanks to all who replied!
AMdeveloper is offline
Reply With Quote
View Public Profile
 
Old 12-14-2007, 04:30 PM Re: PHP echo JavaScript.. FireFox chokes?
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 1,005
Name: Jeremy Miller
Location: Reno, NV
AM: You're actually just approximating when the page loads. According to your script, you're trying to make a page automatically submit a form as soon as the page is loaded. Since page load times vary from user to user (a dialup user, for example, will take longer than an high speed user to load the same page), your script will work sometimes and not others.

Since you're really just redirecting the user based on an error, I'd suggest modifying your code to something like this
PHP Code:
if ($Success != 1) {
  
header("Location:index.php?error=yes");
  exit();

(NOTE: That changes the value to a $_GET value instead of a $_POST value.)

Now, if that doesn't work, it's most likely because you've already returned some text to the browser, so then you'd have to use something like this for the same effect:
PHP Code:
if ($Success != 1) {
  echo 
'<script type="text/javascript">
location.replace("index.php?error=yes");
</script>'
;

All that said, I'd suggest that you've got the logic of your routine wrong -- how likely is it that when an error occurs you need to redirect the user to an error page? I suggest that it really should show the user the error and provide them with the ability to correct it on that page itself -- no redirection involved. That skips the time required to redirect and load the new page and makes the process a bit smoother for your website visitors AND it doesn't require javascript to be enabled.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 12-14-2007, 04:35 PM Re: PHP echo JavaScript.. FireFox chokes?
Novice Talker

Posts: 8
Thanks JM

Yes I know what you mean.. in fact, the form uses it's own script as the action, so the error is shown on the same page. I just wanted to avoid url variable passing... maybe that is the best way though
AMdeveloper is offline
Reply With Quote
View Public Profile
 
Old 12-14-2007, 05:06 PM Re: PHP echo JavaScript.. FireFox chokes?
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 1,005
Name: Jeremy Miller
Location: Reno, NV
I actually recommend NOT redirecting. Something like this for the logical structure:

PHP Code:
<?php
// Process form fields here

if ($Success == 1) {
  
// Processing succeeded, so do whatever it is you do
} else {
  
// Processing failed.
  
echo '<div class="error_message">There was an error, dude.</div>';
?>
<form metod="post" action="index.php">
... Your form fields here.
</form>
<?php
}
?>
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to PHP echo JavaScript.. FireFox chokes?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.16477 seconds with 12 queries