php and javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

php and javascript

Post 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.
tylerdurden
Forum Commoner
Posts: 66
Joined: Mon Jul 28, 2003 11:52 am
Location: Austria

Post 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
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post 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");
tylerdurden
Forum Commoner
Posts: 66
Joined: Mon Jul 28, 2003 11:52 am
Location: Austria

Post 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.
User avatar
liljester
Forum Contributor
Posts: 400
Joined: Tue May 20, 2003 4:49 pm

Post by liljester »

i usually use <?php print"$var"; ?> =)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
User avatar
johnperkins21
Forum Contributor
Posts: 140
Joined: Mon Oct 27, 2003 4:57 pm

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Thanks :p
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

up
User avatar
johnperkins21
Forum Contributor
Posts: 140
Joined: Mon Oct 27, 2003 4:57 pm

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



?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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?
User avatar
johnperkins21
Forum Contributor
Posts: 140
Joined: Mon Oct 27, 2003 4:57 pm

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
User avatar
johnperkins21
Forum Contributor
Posts: 140
Joined: Mon Oct 27, 2003 4:57 pm

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

<?
}
?>
Post Reply