Jump to content

Recommended Posts

Hi to everyone

 

Here's my code:

first_page.html

<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

<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

Link to comment
https://forums.phpfreaks.com/topic/131163-solved-pass-information-through-link/
Share on other sites

Firstly you'll need to use the PHP extension on the file (unless you have configured your server to parse html files?) Then you'll need to pass a parameter through the URL, like so:

 

<a href="second_page.php?link=1">Link 1</a>

 

.. Doesn't have to be "link=1".

 

Then on second_page.php you'll need to use some PHP to decide which option to select, quick and simple way of doing it..

 

<select name="link" id="link">
    <option value="Link 1"<?php if ($_GET['link'] == 1) { echo ' selected'; } ?>>Link 1 was selected</option>
    <option value="Link 2"<?php if ($_GET['link'] == 2) { echo ' selected'; } ?>>Link 2 was selected</option>
    <option value="Link 3"<?php if ($_GET['link'] == 3) { echo ' selected'; } ?>>Link 3 was selected</option>
</select>

 

$_GET['..'] is used to return values sent in the URL, so $_GET['link'] holds the value of '1' if in the URL you had: 'link=1' ..

 

Make sense?

 

Adam

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.