Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 850 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     Javascript :

Call javascript variable in php

Thread title: Call javascript variable in php
Closed Thread  
Page 1 of 2 1 2 >
    Thread tools Search this thread Display Modes  
07-01-2007, 07:18 PM
#1
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old  Call javascript variable in php

I need to call a javascript function in php...

in other words..

make:
var c
into
$c
and so I can use $c in if statements.

07-01-2007, 07:41 PM
#2
Immersion is offline Immersion
Status: Senior Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 918
iTrader: 5 / 100%
 

Immersion is on a distinguished road

  Old

could you not use javascript to call a php function and have it passed through?

07-01-2007, 07:41 PM
#3
Choco is offline Choco
Status: Member
Join date: Jul 2007
Location: USA
Expertise:
Software:
 
Posts: 240
iTrader: 2 / 100%
 

Choco is on a distinguished road

Send a message via MSN to Choco

  Old

You need to pass a javascript variable to a php function?
You could do this:
<script type="text/javascript">
var c="this is my variable";
document.write("<script type='text/javascript' src='myphpfile.php?c="+c+"'></s"+"cript>");
</script>

Then, in your php file:
$c=$_GET['c'];

And then you play with your variable =D

07-01-2007, 08:27 PM
#4
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old

Code:
<script type="text/javascript">
var c = 0
function progress()
	{
		document.getElementById('percent').innerHTML = c + "%"
		c = c + 1
		t = setTimeout( "progress()", 50 )
		if ( c - 1 == 100 ) { clearTimeout( t ) }
	}
</script>
<style type="text/css">
.file 
	{
		height: 22px;
		margin-right: 2px;
		border: 1px #000000 solid;
	}
.submit
	{
		width: 100px;
		border: 1px #000000 solid;
	}
.progress
	{
		background-color: #000000;
		text-align: right; color: #FFFFFF; font-size: 9;
		padding-left: 3px; padding-right: 4px;
		filter: alpha( opacity = 100 );
	}
</style>

<?php
	$max_width = "300"; $width = "";
echo '<input type="file" class="file" style="width: '.($max_width + 83).'px" >';
echo '<input type="submit" class="submit" value="Upload" onClick="progress()">';

echo '<div class="progress" name="progress" style="width: '.$width.'px"><a id="percent"></a></div>';
?>
i dont know if that helps.. but i need to get the c variable and make it the width...

07-01-2007, 09:18 PM
#5
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old

http://s199039163.onlinehome.us/test.php

it doesnt upload anything yet...

07-01-2007, 10:29 PM
#6
Wildhoney is offline Wildhoney
Wildhoney's Avatar
Status: Request a custom title
Join date: Feb 2006
Location: Nottingham
Expertise:
Software:
 
Posts: 1,648
iTrader: 18 / 95%
 

Wildhoney is on a distinguished road

Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney

  Old

PHP is processed before Javascript. I don't understand what you're trying to achieve by doing this. Explain to me why you want to do and there may be a way round it.

07-01-2007, 11:50 PM
#7
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

Why not add an extra line in the JavaScript to change the percentage width?

Code:
...
if ( c - 1 == 100 ) { clearTimeout( t ) }
else { document.getElementById("progress").style.width = c + "px"; }
...
Don't forget to change the 'name' attribute to 'id', else the above change won't really help at all.

With all that said, your code doesn't really seem to be attempting to do anything useful. It'll just animate the progress bar from 0 to 100 pixels over a period of time and then stop. Are you trying to implement some form of upload progress meter to accurately represent the state of the upload?

07-02-2007, 01:15 AM
#8
Seraskier is offline Seraskier
Status: I love this place
Join date: Jan 2007
Location: Charlotte
Expertise:
Software:
 
Posts: 542
iTrader: 0 / 0%
 

Seraskier is an unknown quantity at this point

Send a message via AIM to Seraskier Send a message via MSN to Seraskier

  Old

yeah im trying to make a file upload...

07-02-2007, 01:48 AM
#9
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

PHP cant take a variable from JavaScript, they process at different times, here is what happens under the hood.

Browser makes a request -> Server picks up request -> Server does all server side scripting (php, asp, sql, ect.) -> Server sends processed code back -> Browser gets it -> Browser processes client site code (HTML, JS) -> Browser renders it

So none of the JS doesnt start processing till after the PHP is done. The only way around this to to send a request back to the server via javascript. But I dont know any of that stuff so I cant help you

07-02-2007, 02:14 AM
#10
allstar is offline allstar
Status: Junior Member
Join date: Apr 2007
Location:
Expertise:
Software:
 
Posts: 30
iTrader: 0 / 0%
 

allstar is on a distinguished road

  Old

Ajax -> Pass a php script a javascript variable using get/post, get the output from that file and use it in the present javascript routine.

Look up what Ajax is and how to use it.

Closed Thread  
Page 1 of 2 1 2 >


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed