Pre-selected Option of a Select, coming from different page?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dktea

    #1

    Pre-selected Option of a Select, coming from different page?

    Hello,
    I have a question I hoping someone here could help me. I have a web and in some pages I want to put a contact link, wich will get the user to a diferent page. So in depending on witch page the user comes from I want to preselect an option on a select.

    For example I am in this page mobile-web-design.php and there is a link named Contact Us, witch takes me to the contact.php. In the contact.php, there is a select with several Subjects, for example, Mobile Web Design, Graphic Design etc... so I want to preselect the "Mobile Web Design" Subject.

    Thank you!
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Use a session variable. And assign it a value when a visitor visits each of those pages except for the contact page.

    On the contact page the session variable will contain the name of the last page they visited.

    On each page:
    Code:
    $_SESSION['subject'] = 'Name of This Page';
    On the contact page:

    Code:
    <select>
       <option value="page1" <?php if $_SESSION['subject'] == 'page 1' echo "selected='selected'"; ?>>Page One</option>
       <option value....
    .
    .
    .
    </select>
    Make sense?


    Dan

    Comment

    • kamran sohail
      New Member
      • Oct 2010
      • 1

      #3
      I am agree with dlite922 this is the most easier way to do this. We can also do this by getting the file name
      if($file=="mobi le-web-design.php") {
      $subject = mobile web design;
      }
      and place the subject in the contact link
      <a href="contact.p hp?subject=<?ph p echo $subject;?>"Con tact</a>

      Its up to you which way you adopt, but I still prefer dlite922 approach

      Comment

      Working...