469,601 Members | 2,450 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,601 developers. It's quick & easy.

Can this javascript be replaced by pure PHP ?

I don't know how to explain this action, basically a web page will show
a brief format and there'll be a link the says "show more" and when
clicked more text shows. eg. goto

http://www.newegg.com/app/ViewProduc...19-101&depa=10

and scroll down to the customer reviews, you'll see some reviews have a
link named "See complete" - and that's the action I want. They are doing
that will javascript. Is there a way to do this with pure php?

Thanks
Jul 17 '05 #1
14 1877
>
http://www.newegg.com/app/ViewProduc...19-101&depa=10

and scroll down to the customer reviews, you'll see some reviews have a link named "See complete" - and that's the action I want. They are doing that will javascript. Is there a way to do this with pure php?


About the only way you could do this server-side is by repainting the
entire page. That is, the "See complete" link would simply be <a
href="mypage.php?open=1">See complete</a> and your page would check for
$_REQUEST['open']==1 and conditionally paint the entire text.

--cd
Jul 17 '05 #2
Also sprach leegold2:
http://www.newegg.com/app/ViewProduc...19-101&depa=10
and scroll down to the customer reviews, you'll see some reviews have
a link named "See complete" - and that's the action I want. They are
doing that will javascript. Is there a way to do this with pure php?


Sure. The reviews are read from a database, I suppose, and are to be shown
either "complete" or "incomplete". Assign an id to each review in PHP and
make the "See complete" links something like
http://foo.bar/page.php?showcomplete=id&showothers=xxx, where id is the id
of this review and xxx somehow represents the state of the other reviews
(e.g. a binary number where set/reset bits mean that the corresponding
review is complete/incomplete). Then have your PHP script look for the
variables showcomplete and showothers and use this information to generate
the page, including the "See complete" links with the updated showothers
variable. There may be other ways to achieve the same result, but this is
the one that first came to my mind.

Jul 17 '05 #3
leegold2 <le*****@nospam.net> wrote in message news:<9Dgid.95$2c5.16@trnddc01>...
I don't know how to explain this action, basically a web page will show
a brief format and there'll be a link the says "show more" and when
clicked more text shows. eg. goto

http://www.newegg.com/app/ViewProduc...19-101&depa=10

and scroll down to the customer reviews, you'll see some reviews have a
link named "See complete" - and that's the action I want. They are doing
that will javascript. Is there a way to do this with pure php?

Thanks


not really.

the complete text of the review is already included in the doc from
the start, but only partly visible. the javascript just toggles the
visibility of the second part of the text. this is done pure
clientside and therefore impossible with php.

a similar behaviour done in php could work like this:

1. user requests page, display page with 1st part of text

2. user clicks 'view comlete', this request is sent back to the server
and includes some information about how to view the page

3. php generates and sends the page again, this time showing the whole
text

micha
Jul 17 '05 #4
leegold2 <le*****@nospam.net> wrote in message news:<9Dgid.95$2c5.16@trnddc01>...
I don't know how to explain this action, basically a web page will show
a brief format and there'll be a link the says "show more" and when
clicked more text shows. eg. goto

http://www.newegg.com/app/ViewProduc...19-101&depa=10

and scroll down to the customer reviews, you'll see some reviews have a
link named "See complete" - and that's the action I want. They are doing
that will javascript. Is there a way to do this with pure php?

Thanks


PHP is server-side
Javascript and CSS are client side.

Your answer is "no"
you could have the "show complete" load a new page and change it up
however you want. (rather than the "dynamic html" stuff)
Jul 17 '05 #5
>
PHP is server-side
Javascript and CSS are client side.

Your answer is "no"
Thank you all for the posts and the information. Maybe this is case were
I want to sprinkle in a little javascript, as lttle as possible.


you could have the "show complete" load a new page and change it up
however you want. (rather than the "dynamic html" stuff)

Jul 17 '05 #6
> this is done pure
clientside and therefore impossible with php.


Micha didn't really push how important this distinction is. You're
trying to make a server-side language do client-side work.

PHP is a great language because it is server-side and therefore we
have complete control over it. JavaScript on the other hand is run by
the browser of the person accessing the webpage; of course we have no
control over what version of browser or whatever they're using.

There are two commonly taken approaches to this quandry.
A) Drop javascript for a couple of years
B) Pander to every browser and make sure it works perfectly (you might
note that this is only worth doing in the case that the JavaScript is
extremely important. In the case of opening reviews it's kinda
pointless but newegg has a lot of money to throw around)

Option A involves no risk at all. Option B can drive a business into a
giant hole by estranging customers. (Can you tell which side I'm on?)
Jul 17 '05 #7
I noticed that Message-ID: <gIzid.2007$Uy5.101@trnddc07> from leegold2
contained the following:

Thank you all for the posts and the information. Maybe this is case were
I want to sprinkle in a little javascript, as lttle as possible.


Indeed, JavaScript should only be used for non critical applications. If
you make the entire review accessible /only/ to people with JavaScript
enabled then a significant number of people will not have access to it.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #8
Also sprach Chuck Vose:

[No control over client side JavaScript]
There are two commonly taken approaches to this quandry.
A) Drop javascript for a couple of years
Why "a couple of years"? Do you think in 2010 web designers will have
complete remote comtrol over every client's PC?
B) Pander to every browser and make sure it works perfectly (you might
note that this is only worth doing in the case that the JavaScript is
extremely important. In the case of opening reviews it's kinda
pointless but newegg has a lot of money to throw around)


C) (Not necessarily in contradiction with the other two) Minimize the need
for using JavaScript (thus: no JavaScript needed on most pages). Use
JavaScript in a way that will ensure the site's usability even when
JavaScript or some of its features are not supported by the client.
Jul 17 '05 #9
You can do it without Javascript, but the page has to be refreshed...
(Which really shouldnt be a HUGE problem.)

Just assign a variable when the link is clicked. Say you have this
script on index.php make your href: index.php?show_more=1

Then use an if statement to check for that variable, and if it is there
then show them what they want to see, if it is not, show the link to
"show more" IE:

if ($show_more) {
echo 'The Stuff You Want To See!';
}

else {
echo '<a href="index.php?show_more=1">Show me more</a>';
}

I hope that helps...
leegold2 wrote:
I don't know how to explain this action, basically a web page will show a brief format and there'll be a link the says "show more" and when
clicked more text shows. eg. goto

http://www.newegg.com/app/ViewProduc...19-101&depa=10
and scroll down to the customer reviews, you'll see some reviews have a link named "See complete" - and that's the action I want. They are doing that will javascript. Is there a way to do this with pure php?

Thanks


Jul 17 '05 #10
Chuck Vose wrote:
this is done pure
clientside and therefore impossible with php.

Micha didn't really push how important this distinction is. You're
trying to make a server-side language do client-side work.


I understand the distiction now. I'm just going to test on the recent
versions of IE, MOZ/NS and Opera. If I sense a browser's not JS enabled
I sidestep the javascript for that instance.

.....snip...

There are two commonly taken approaches to this quandry.
A) Drop javascript for a couple of years
B) Pander to every browser and make sure it works perfectly (you might
note that this is only worth doing in the case that the JavaScript is
extremely important. In the case of opening reviews it's kinda
pointless but newegg has a lot of money to throw around)

Option A involves no risk at all. Option B can drive a business into a
giant hole by estranging customers. (Can you tell which side I'm on?)


I'm not a fan of JS either.
Jul 17 '05 #11
John Postlethwait wrote:
You can do it without Javascript, but the page has to be refreshed...
(Which really shouldnt be a HUGE problem.)
Should I worry about accessing the MYSQL repeated times? It seems to
"look" better if the page's not refreshed. I vastly prefer PHP but it
seems like...I'll have to think about it more...


Just assign a variable when the link is clicked. Say you have this
script on index.php make your href: index.php?show_more=1

Then use an if statement to check for that variable, and if it is there
then show them what they want to see, if it is not, show the link to
"show more" IE:

if ($show_more) {
echo 'The Stuff You Want To See!';
}

else {
echo '<a href="index.php?show_more=1">Show me more</a>';
}

I hope that helps...
leegold2 wrote:
I don't know how to explain this action, basically a web page will


show
a brief format and there'll be a link the says "show more" and when
clicked more text shows. eg. goto


http://www.newegg.com/app/ViewProduc...19-101&depa=10
and scroll down to the customer reviews, you'll see some reviews have


a
link named "See complete" - and that's the action I want. They are


doing
that will javascript. Is there a way to do this with pure php?

Thanks


Jul 17 '05 #12
I as a JS and PHP developer see an odvious solution that no one else
seems to see.
Use both Javascript *and* PHP
This might take a lot more work is some applications, but everything
works on non JS browsers and works instantaneously on JS browsers.
something like:
<a href="index.php?more=1" onclick="this.href='#';more(this)">Show full
review</a>
the more() JS function will be run if JS works and no page will br
loaded.
In non-JS supporting browsers, index.php(or the page that it is on)
gets passed to a $_GET variable(should be accessed vie $_REQUEST
thought)
all the ways mentioned above using $_REQUEST etc. could be used plus a
simple JavaScript.
This javascript would have to take into account page structure so I
wont write it out now(this is also a PHP NG not a JS one).
hope that helps
--Infinull

Jul 17 '05 #13
Also sprach leegold2:
Should I worry about accessing the MYSQL repeated times? It seems to
"look" better if the page's not refreshed. I vastly prefer PHP but it
seems like...I'll have to think about it more...


Another option: Let non-JavaScript users see the full text of all reviews
and give JavaScript users the incomplete review with the option to
"complete" it. If there are too many reviews per page, split them into
multiple pages. Simple and everyone is happy.

Jul 17 '05 #14
Also sprach in******@yahoo.com:
I as a JS and PHP developer see an odvious solution that no one else
seems to see.
Use both Javascript *and* PHP
This might take a lot more work is some applications, but everything
works on non JS browsers and works instantaneously on JS browsers.
something like:
<a href="index.php?more=1" onclick="this.href='#';more(this)">Show
full review</a>
the more() JS function will be run if JS works and no page will br
loaded.
In non-JS supporting browsers, index.php(or the page that it is on)
gets passed to a $_GET variable(should be accessed vie $_REQUEST
thought)


The page would need to contain the full text of every review, part of which
would have to be hidden using CSS. PHP could "toggle" between full and
incomplete views assigning two CSS classes accordingly. But then it would be
simpler to simply show non-JavaScript users the full text. It won't kill
them.

Jul 17 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jim | last post: by
15 posts views Thread by binnyva | last post: by
2 posts views Thread by Mtek | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.