Page 1 of 2

php and javascript

Posted: Wed Feb 18, 2004 10:15 am
by John Cartwright
Using this

Code: Select all

<?php
<script language=javascript> 
function openwin() { 
  window.open("page.php", "title", "toolbar=0,status=0,menubar=0,scrollbars=no,resizable=no,width=315,height=400"); 
} 
</script> 

?>
How can I pass variables from a form in the next popup.
Ie. page.php?opponent=$opponent

When I try to simply add that into the url on the popup window I actually get the variable name instead of its value.

Posted: Wed Feb 18, 2004 11:04 am
by tylerdurden
If I understand you correctly I think you'd have to use something like

Code: Select all

page.php?varname=<?PHP echo $varname?>
as the URL

Posted: Wed Feb 18, 2004 11:08 am
by liljester
ive used this before, and it works:

Code: Select all

window.open("page.php?opponent="<?=$opponent?>", "title", "toolbar=0,status=0,menubar=0,scrollbars=no,resizable=no,width=315,height=400");

Posted: Wed Feb 18, 2004 11:35 am
by tylerdurden
<?=$opponent?> is the short form of <?PHP echo $opponent?>. I've seen more than 1 server where short PHP tags were disabled (dont ask me why), so use the normal form unless you have control over the server.

Posted: Wed Feb 18, 2004 11:37 am
by liljester
i usually use <?php print"$var"; ?> =)

Posted: Wed Feb 18, 2004 2:26 pm
by John Cartwright
Just a quick question, one that is sorta confusing me.

If I put the javascript at the top of a page with lets say:

page.php?varname=<?PHP echo $varname?> then I begin my php script, which determines the variables through a form ( so the page reloads when submit is clicked ) the javascript will pick up the vars on realod right.

Posted: Wed Feb 18, 2004 2:30 pm
by johnperkins21
Phenom,
I just had a similar issue. The form needs to be submitted, you can't just reload the page. If I'm understanding your question right. Here's the link to my post: viewtopic.php?t=18294.

Good luck.

Posted: Wed Feb 18, 2004 2:32 pm
by John Cartwright
Thanks :p

Posted: Wed Feb 18, 2004 2:53 pm
by John Cartwright

Code: Select all

<?php
        echo "</font><form action="admin.php"\n".  
					"<div align="left"> \n".
            		"<table width="100%" border="0" cellpadding="0" cellspacing="0">\n".
              			"<tr> \n".
                 			"<td height="19">&nbsp;</td>\n".
                			"<td>&nbsp;</td>\n".
              			"</tr>\n".
              			"<tr> \n".
                			"<td height="19"><font face="Arial, Helvetica, sans-serif"><strong><font color="#990000">MATCH SUBMIT</font></strong></font></td>\n".
                			"<td>&nbsp;</td>\n".
              			"</tr>\n".
              			"<tr> \n".
                			"<td height="22">&nbsp;</td>\n".
                			"<td>&nbsp;</td>\n".
              			"</tr>\n".
              			"<tr> \n".
                			"<td width="42%" height="22"><font face="Arial, Helvetica, sans-serif">Opponent:</font></td>\n".
                			"<td width="58%"><font face="Arial, Helvetica, sans-serif"> \n".
                  					"<input name="opponent" type="text" id="opponent3"></font></td>\n".
              			"</tr>\n".
              			"<tr> \n".
                			"<td><font face="Arial, Helvetica, sans-serif">League</font></td>\n".
                			"<td width="58%"><font face="Arial, Helvetica, sans-serif"> \n".
                  					"<select name="league" size="1" id="select3">\n".
                    				"<option>cal</option>\n".
                    				"<option>scrim</option>\n".
                  					"</select>\n".
                  					"</font></td>\n".
              			"</tr>\n".
              			"<tr> \n".
                			"<td><font face="Arial, Helvetica, sans-serif">Date (yyyy-mm-dd):</font></td>\n".
                			"<td width="58%"><font face="Arial, Helvetica, sans-serif"> \n".
                  					"<input name="date" type="text" id="date5"></font></td>\n".
              			"</tr>\n".
              			"<tr> \n".
                			"<td><font face="Arial, Helvetica, sans-serif">Map</font></td>\n".
                			"<td width="58%"> <font face="Arial, Helvetica, sans-serif"> \n".
                  					"<select name="map">\n".
                    				"<option>de_dust2</option>\n".
                    				"<option>de_aztec</option>\n".
                    				"<option>de_nuke</option>\n".
                    				"<option>de_train</option>\n".
                    				"<option>de_cpl_fire</option>\n".
                    				"<option>de_cpl_mill</option>\n".
                    				"<option>de_inferno</option>\n".
                    				"<option>de_comrade</option>\n".
                    				"<option>de_chateau</option>\n".
                  					"</select></font>\n".
						    "</td>\n".
              			"</tr>\n".
              			"<tr> \n".
                			"<td><font face="Arial, Helvetica, sans-serif">Outcome </font></td>\n".
                			"<td width="58%"> <font face="Arial, Helvetica, sans-serif"> \n".
                  					"<select name="outcome" size="1" id="select6">\n".
                    				"<option>win</option>\n".
                    				"<option>loss</option>\n".
                    				"<option>tie</option>\n".
                  					"</select></font>\n".
                  			"</td>\n".
              			"</tr>\n".
            "</table>\n".
            
			"<font face="Arial, Helvetica, sans-serif"><br>\n".
            "<input type="submit" name="submitrecord" value="SUBMIT">\n".
            "</font></div>\n".
        	"</form>\n";
        

if ($submitrecord=="SUBMIT"){

?>	

<script language=javascript> 
function openwin() { 
  window.open("admin_confirm.php?<? echo "opponent=$opponent&date=$date&map=$map&league=$league&outcome=$outcome;" ?>", "title", "toolbar=0,status=0,menubar=0,scrollbars=no,resizable=no,width=315,height=400"); 
} 
</script>
This is really weird, when the form is submitted and it gives $submitrecord the value of submit it is like it ignore thes if $submitrecrd==submit completely. I tried a few simple echos to see if it was working and nothing. Am I missing a stupid litttle error?

Posted: Wed Feb 18, 2004 3:50 pm
by John Cartwright
up

Posted: Wed Feb 18, 2004 4:22 pm
by johnperkins21
Phenom wrote:

Code: Select all

if ($submitrecord=="SUBMIT"){

?>	

<script language=javascript> 
function openwin() { 
  window.open("admin_confirm.php?<? echo "opponent=$opponent&date=$date&map=$map&league=$league&outcome=$outcome;" ?>", "title", "toolbar=0,status=0,menubar=0,scrollbars=no,resizable=no,width=315,height=400"); 
} 
</script>
This is really weird, when the form is submitted and it gives $submitrecord the value of submit it is like it ignore thes if $submitrecrd==submit completely. I tried a few simple echos to see if it was working and nothing. Am I missing a stupid litttle error?

It doesn't look like you're closing your if statement. You need to go back into php for the }

Try:

Code: Select all

<?php
if ($submitrecord=="SUBMIT"){ 

?>    

<script language=javascript> 
function openwin() { 
  window.open("admin_confirm.php?<? echo "opponent=$opponent&date=$date&map=$map&league=$league&outcome=$outcome;" ?>", "title", "toolbar=0,status=0,menubar=0,scrollbars=no,resizable=no,width=315,height=400"); 

<?  #Go back into php 
}
?> 
</script> 



?>

Posted: Wed Feb 18, 2004 4:28 pm
by John Cartwright
Sorry I'm retarded, but I am infact closing that if statement, just I didnt copy and paste my code properly.

The problem now is taht the function is not being called, but when I set the function in a link it works fine.

How do I make that function load in that if statement without the use of a link?

Posted: Wed Feb 18, 2004 4:35 pm
by johnperkins21
Is there somewhere else where you're calling the function?? It looks like you're only creating the function in the if statement, but never calling it anywhere.

Posted: Wed Feb 18, 2004 4:37 pm
by John Cartwright
No I'm not too familiar with javascript, i don't know how to call the function without using a link.. ie. onload

Posted: Wed Feb 18, 2004 4:40 pm
by johnperkins21
Try it without the function winopen() part. i.e.:

Code: Select all

<?php
if ($submitrecord=="SUBMIT") { 

<script language=javascript> 

  window.open("admin_confirm.php?<? echo "opponent=$opponent&date=$date&map=$map&league=$league&outcome=$outcome;" ?>", "title", "toolbar=0,status=0,menubar=0,scrollbars=no,resizable=no,width=315,height=400"); 
</script> 

<?
}
?>