For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > August 2005 > nOOb question...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author nOOb question...
Mich

2005-08-30, 6:56 pm

Sorry, but i'm not all that good in this.

I have this:
<a href="#" onClick="frames['winkels'].location.href =
'storelocator2.php?postcode=3500'; return false">Test</a>

Which works great, it transfers the variable into the iframe, which takes it
and handles it into its own php.


Now i need also to call this same thing from php (it transfers the variable
from a GET method):

<?php
if (isset($_GET['postcode']))
{
$invoer = $_GET['postcode'];
frames["winkels"].location.href =
"storelocator2.php?postcode="+$invoer; <------!!!
}
?>

The line with the <----!!!!! is (offcourse) not working. Where am i going
wrong?
No problem with calling me a noob ;)



ZeldorBlat

2005-08-30, 9:55 pm

What exactly is the error you're getting?

My guess is that you're getting something about a parse error --
because you're trying to mix JavaScript with PHP.

Remeber that that JavaScript runs client side -- which means the code
needs to be output to the browser along with the HTML. I think what
you really want is something like this:

<?php
if(isset($_GET['postcode'])) {
$invoer = $_GET['postcode'];
?>
frames["winkels"].location.href = "storelocator2.php?postcode=" +
<?
php echo $invoer; ?>;
<?php } ?>

The idea is that you can escape between HTML and PHP code and it will
usually behave as expected. Anything between the <?php and ?> will be
parsed as PHP; the rest will be sent straight to the browser.

Kimmo Laine

2005-08-31, 7:55 am

"Kleist" <kleist@tlen.pl> wrote in message
news:df3qf1$19e5$2@news.uar.net...
> ZeldorBlat wrote:
>
>
> Does this "+" mean string concatination?


It does, in javaScript.

--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
eternal piste erection miuku gmail piste com


Mich

2005-08-31, 7:55 am

----- Original Message -----
From: "ZeldorBlat" <zeldorblat@gmail.com>
Newsgroups: alt.comp.lang.php
Sent: 31 August, 2005 03:02
Subject: Re: nOOb question...


> What exactly is the error you're getting?
>
> My guess is that you're getting something about a parse error --
> because you're trying to mix JavaScript with PHP.
>
> Remeber that that JavaScript runs client side -- which means the code
> needs to be output to the browser along with the HTML. I think what
> you really want is something like this:
>
> <?php
> if(isset($_GET['postcode'])) {
> $invoer = $_GET['postcode'];
> ?>
> frames["winkels"].location.href = "storelocator2.php?postcode=" +
> <?
> php echo $invoer; ?>;
> <?php } ?>
>
> The idea is that you can escape between HTML and PHP code and it will
> usually behave as expected. Anything between the <?php and ?> will be
> parsed as PHP; the rest will be sent straight to the browser.
>


Thankx Zeldor,

Had to adjust a little, but got it working in the end.

<?php
if (isset($_GET['postcode']))
{
$invoer = $_GET['postcode'];
?>
<script type="text/javascript">
var whatever = "<?= $invoer ?>";
frames['winkels'].location.href = 'storelocator2.php?postcode=' +
whatever
</script>
<?php
}
?>

For some reason this: frames["winkels"].location.href =
"storelocator2.php?postcode=" +<?php echo $invoer; ?>;
didn't get any characters through, though it did numbers.

Also:
frames['winkels'].location.href = 'storelocator2.php?postcode=' + "<?=
$invoer ?>"
Works well.

Thankx for the help, very much appreciated.



Kimmo Laine

2005-08-31, 7:55 am

"Mich" <PleaseAskInThread@nl.nl> wrote in message
news:43159479$0$11061$e4fe514c@news.xs4all.nl...
> ----- Original Message -----
> From: "ZeldorBlat" <zeldorblat@gmail.com>
> Newsgroups: alt.comp.lang.php
> Sent: 31 August, 2005 03:02
> Subject: Re: nOOb question...
>
>
>
> Thankx Zeldor,
>
> Had to adjust a little, but got it working in the end.
>
> <?php
> if (isset($_GET['postcode']))
> {
> $invoer = $_GET['postcode'];
> ?>
> <script type="text/javascript">
> var whatever = "<?= $invoer ?>";
> frames['winkels'].location.href = 'storelocator2.php?postcode=' +
> whatever
> </script>
> <?php
> }
> ?>



This should also work:
<?php if (isset($_GET['postcode'])){ ?>
<script type="text/javascript">
frames['winkels'].location.href = 'storelocator2.php?postcode=<?=
$_GET['postcode'] ?>';
</script>
<?php } ?>

--
Welcome to Usenet! Please leave tolerance, understanding
and intelligence at the door. They aren't welcome here.
eternal piste erection miuku gmail piste com


ZeldorBlat

2005-08-31, 6:55 pm

Yeah, that's how I would normally write it...with the short tags. But
I figure if you're just learning, you might as well get into the habbit
of the full open tags since people these days seem to think that
they're bad :)

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com