Page 1 of 1
Pass information through link
Posted: Mon Nov 03, 2008 3:07 am
by Batric
Hi to everyone
Here's my code:
first_page.html
Code: Select all
<html>
<head>
<title>First</title>
</head>
<body>
<a href="second_page.html">Link 1</a><br />
<a href="second_page.html">Link 2</a><br />
<a href="second_page.html">Link 3</a>
</body>
</html>
second_page.html
Code: Select all
<html>
<head>
<title>Second</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="link" id="link">
<option value="Link 1">Link 1 was selected</option>
<option value="Link 2">Link 2 was selected</option>
<option value="Link 3">Link 3 was selected</option>
</select>
</label>
</form>
</body>
</html>
How to connect these two pages, so when I click on
Link 2 on the first page, the second pages opens and the
Link 2 was selected is choosed?
Thank you in any case
Batric
Re: Pass information through link
Posted: Mon Nov 03, 2008 3:31 am
by pavanpuligandla
Code: Select all
[quote]first_page.html
Line number On/Off | Expand/Contract
1. <html>
2. <head>
3. <title>First</title>
4. </head>
5. <body>
6. <a href="second_page.html">Link 1</a><br />
7. <a href="second_page.html">Link 2</a><br />
8. <a href="second_page.html">Link 3</a>
9. </body>
10. </html>
11. [/quote]
simply change href's in the first page as
Code: Select all
<a href="second_page_link1.html">Link 1</a><br />
make link1 appear in the second page and the rest 2 invisible.
Code: Select all
<a href="second_page_link2.html">Link 2</a><br />
make link2 appear in the secondpage and the rest 2 invisible
is thisyou want to do?
Re: Pass information through link
Posted: Mon Nov 03, 2008 3:33 am
by aceconcepts
I've amended your script. This should work for you:
Batric wrote:Hi to everyone
Here's my code:
first_page.html
Code: Select all
<html>
<head>
<title>First</title>
</head>
<body>
<a href="second_page.html?link=1">Link 1</a><br />
<a href="second_page.html?link=2">Link 2</a><br />
<a href="second_page.html?link=3">Link 3</a>
</body>
</html>
second_page.html
Code: Select all
<html>
<head>
<title>Second</title>
</head>
<body>
<?
//GET link VARIABLE FROM URL
if(isset($_REQUEST['link']) && !empty($_REQUEST['link']))
{
$link=$_REQUEST['link'];
}
?>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="link" id="link">
<option value="Link 1" <? if($link==1){ echo'selected="selected"'; ?>>Link 1 was selected</option>
<option value="Link 2" <? if($link==2){ echo'selected="selected"'; ?>>Link 2 was selected</option>
<option value="Link 3" <? if($link==3){ echo'selected="selected"'; ?>>Link 3 was selected</option>
</select>
</label>
</form>
</body>
</html>
How to connect these two pages, so when I click on
Link 2 on the first page, the second pages opens and the
Link 2 was selected is choosed?
Thank you in any case
Batric
Re: Pass information through link
Posted: Mon Nov 03, 2008 3:47 am
by requinix
You have a couple unclosed if{...} blocks in there. And $link would be undefined if someone got to the second page without a &link=.
Code: Select all
<html>
<head>
<title>Second</title>
</head>
<body>
<?
//GET link VARIABLE FROM URL
if(isset($_REQUEST['link']) && !empty($_REQUEST['link']))
{
$link=$_REQUEST['link'];
}
else
{
$link=0;
}
?>
<form id="form1" name="form1" method="post" action="">
<label>
<select name="link" id="link">
<option value="Link 1" <? if($link==1) echo 'selected="selected"'; ?>>Link 1 was selected</option>
<option value="Link 2" <? if($link==2) echo 'selected="selected"'; ?>>Link 2 was selected</option>
<option value="Link 3" <? if($link==3) echo 'selected="selected"'; ?>>Link 3 was selected</option>
</select>
</label>
</form>
</body>
</html>
Seriously, who indents using
three spaces? Two yes, four yes, even eight, but three?
Re: Pass information through link
Posted: Mon Nov 03, 2008 3:57 am
by Batric
@aceconcepts
That's what I looked for
Thank you a lot!

Re: Pass information through link
Posted: Mon Nov 03, 2008 7:17 am
by Batric
tasairis wrote:
Seriously, who indents using three spaces? Two yes, four yes, even eight, but three?
If you think of my post - I used Dreamweaver

Re: Pass information through link
Posted: Mon Nov 03, 2008 7:51 am
by aceconcepts
@tasairis
What's the deal with indents??? Who cares how many spaces there are.
Concentrate more on solving the issue at hand.
@Batric
I'm glad it worked for you

Re: Pass information through link
Posted: Mon Nov 03, 2008 9:01 am
by Batric
I have one more question:
How can I connect some random object and php? Here's the example:
Code: Select all
<html>
<body>
<img name="first" src="" width="32" height="32" alt="">
<img name="second" src="" width="32" height="32" alt="">
<img name="third" src="" width="32" height="32" alt="">
<img name="fourth" src="" width="32" height="32" alt="">
<img name="fifth" src="" width="32" height="32" alt="">
</body>
</html>
When I click on first image, the value of $test should be
first etc
Any ideas?
Thanks again
Re: Pass information through link
Posted: Mon Nov 03, 2008 9:36 am
by aceconcepts
You could place the image within a hyperlink:
Code: Select all
<a href="?test=first"><img name="first" src="" width="32" height="32" alt=""></a>
and then do the same as before, with regard to $_REQUEST[''] etc...
Re: Pass information through link
Posted: Mon Nov 03, 2008 5:08 pm
by Batric
That would be it, but the page should not reload.
Do you know how to do it with ajax?