11 replies [Last post]
Howard
Offline
Regular
Last seen: 17 years 18 weeks ago
Joined: 2005-07-29
Posts: 14
Points: 0

When I click on any of the items (after the first one) in the drop-down box in the Cushing's Education section, its link isn't working? What's wrong?

The code's at http://home.comcast.net/~anotherhoward/prototype1.htm

Howard

P.S. If the link to the code didn't work for you, it was because it included a period that was at the end of the link, which I've removed.

Tags:
HellsBells
HellsBells's picture
Offline
Leader
Bedford, UK
Last seen: 14 years 30 weeks ago
Bedford, UK
Joined: 2004-04-07
Posts: 851
Points: 0

Why aren't my first drop-down box's links working?

To my knowledge (and I stand to be corrected on this one) links in dropdown boxes only work with a script of some kind attached either Javascript, PHP or ASP.

Another problem with this type of link box (once working with JS or whatever) is that I've yet to come across one that's valid in XHTML 1.0 because the script usually uses the name attribute to function. I don't know if it's possible to switch the trigger from "name" to "title" but I know that "id" doesn't work 'cos I tried it!

My strategy is so simple an idiot could have devised it!

"Also, your CSS (no offence) makes me want to gouge my eyes out with a rusty spoon" - TPH

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 1 year 38 weeks ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9776
Points: 3858

Why aren't my first drop-down box's links working?

The option's value attribute may only contain cdata, that is, text not links.

The easiest way to accomplish using select dropdowns for menus, is to use server-side scripting to send back a redirect. There should also be a graceful failover, some means of clicking through even if the browser doesn't support redirect headers.

 
[a plain text file named go.php in this case] 
 
<? header('location:  '. $where) ?> 
 
<? echo "If you aren't sent to the page, click this link, 
  <a href=\"" . $where . "\">Send me on</a>" ?>

The form would look something like this;
 
<form action="go.php" 
      method="get"> 
  <fieldset> 
    <select name="where"> 
      <option value="http://www.debian.org/"> 
        Debian 
      </option> 
      <option value="http://www.w3.org/"> 
        W3 
      </option> 
    </select>  
    <input type="submit" 
           value="send me" /> 
  </fieldset> 
</form>

Note that the url must be complete, i.e. it must include the protocol and host.

Any server side language should have a similar syntax, but stripping out the option value may not be as simple as it is in PHP.

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

HellsBells
HellsBells's picture
Offline
Leader
Bedford, UK
Last seen: 14 years 30 weeks ago
Bedford, UK
Joined: 2004-04-07
Posts: 851
Points: 0

Why aren't my first drop-down box's links working?

Gary

My PHP skills aren't up to much yet - so I tend to find existing scripts and make them work how I want to. I searched for AGES to find a script that did this last week and couldn't find one that worked and was valid xhtml strict.

I want to have your children.

My strategy is so simple an idiot could have devised it!

"Also, your CSS (no offence) makes me want to gouge my eyes out with a rusty spoon" - TPH

Howard
Offline
Regular
Last seen: 17 years 18 weeks ago
Joined: 2005-07-29
Posts: 14
Points: 0

Why aren't my first drop-down box's links working?

Gary,

As I've never worked with PHP before, I have a few questions about your code.

Am I correct that what you're advising is for me to create a text file, name it "go.php," save it into the same directory as the one that contains my prototype1.htm code, and insert into go.php these two lines of code:

<? header('location: '. $where) ?>

<? echo "If you aren't sent to the page, click this link,
<a href=\"" . $where . "\">Send me on</a>" ?>

--------------------------------------------------------------
Also, if the first line of code doesn't redirect the user to my link, does the second line of code give the user the option to click a link that will take him to the same location?

Howard

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 1 year 38 weeks ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9776
Points: 3858

Why aren't my first drop-down box's links working?

Howard: Yep, That's exactly how it works.

HellsBells: Mighty presumptuous of you; I'd want to meet your wife before committing. Laughing out loud

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

HellsBells
HellsBells's picture
Offline
Leader
Bedford, UK
Last seen: 14 years 30 weeks ago
Bedford, UK
Joined: 2004-04-07
Posts: 851
Points: 0

Why aren't my first drop-down box's links working?

kk5st wrote:
Howard: Yep, That's exactly how it works.

HellsBells: Mighty presumptuous of you; I'd want to meet your wife before committing. Laughing out loud

cheers,

gary

I am the wife!

My strategy is so simple an idiot could have devised it!

"Also, your CSS (no offence) makes me want to gouge my eyes out with a rusty spoon" - TPH

Lorraine
Lorraine's picture
Offline
Elder
UK
Last seen: 16 years 14 weeks ago
UK
Timezone: GMT+1
Joined: 2005-01-04
Posts: 1001
Points: 0

Why aren't my first drop-down box's links working?

Phew! Glad that's out in the open, now I don't have to keep typing s/he anymore Laughing out loud

HellsBells
HellsBells's picture
Offline
Leader
Bedford, UK
Last seen: 14 years 30 weeks ago
Bedford, UK
Joined: 2004-04-07
Posts: 851
Points: 0

Why aren't my first drop-down box's links working?

I know, I know - I should have had a flower or a kitten as an avatar then there wouldn't be any confusion! Laughing out loud

My strategy is so simple an idiot could have devised it!

"Also, your CSS (no offence) makes me want to gouge my eyes out with a rusty spoon" - TPH

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 1 year 38 weeks ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9776
Points: 3858

Why aren't my first drop-down box's links working?

With help from ChiefWigs1982 and Kravvitz over at DevShed, I got some javascript validation and redirection going. The final version is triple redundant. The js validates that the value is not null and sets the form's action to the selected value. If is null, an alert is issued. Should the js fail, a request is made for the server side redirector, and should it fail, a simple html link is presented.

Server-side validation is needed, and both validators should check for a well formed url.

Here is the test case form plus two variations.

 
  <form action="go.php" 
        method="get" 
        onsubmit="var s=this.where; 
                  if (s.options[s.selectedIndex].value!=''){ 
                     this.action=s.options[s.selectedIndex].value; 
                     return true; 
                  } 
                  else { 
                     alert ('You must choose a menu item'); 
                     return false; 
                  }">  
 
    <fieldset> 
      <legend> 
        Triple redundancy 
      </legend> 
      <select name="where"> 
        <option value=""> 
          Where to? 
        </option> 
        <option value="http://www.debian.org/"> 
          Debian 
        </option> 
        <option value="http://www.mozilla.org/"> 
          Mozilla 
        </option> 
      </select>  
      <input type="submit" 
             value="send me" /> 
    </fieldset> 
  </form> 
============== 
  <form action="go.php" 
        method="get" 
        onsubmit="var s=this.where; 
                  return (s.options[s.selectedIndex].value!='')">  
    <fieldset> 
      <legend> 
        Server side redirect—js validation 
      </legend> 
  ... 
================= 
  <form action="#" 
        method="get" 
        onsubmit="var s=this.where; 
                  if(s.options[s.selectedIndex].value!='') {  
                     window.location.href=s.options[s.selectedIndex].value;}  
                  return false;"> 
    <fieldset> 
      <legend> 
        javascript redirect with validation 
      </legend>


Here is the go.php. Notice that validation needs to be added.
 
<? header ('location: '. $where) ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
 
<html xml:lang="en" 
      xmlns="http://www.w3.org/1999/xhtml" 
      lang="en"> 
<head> 
  <meta name="generator" 
        content= 
        "HTML Tidy for Linux/x86 (vers 1st August 2004), see www.w3.org" /> 
         
  <meta name="editor" 
        content="Emacs 21" /> 
  <meta name="author" 
        content="Gary Turner" /> 
  <meta http-equiv="content-type" 
        content="text/html; charset=utf-8" /> 
 
  <title>Send me on</title> 
<style type="text/css"> 
/*<![CDATA[*/ 
 
html, body { 
    margin: 0; 
    padding: 0; 
    } 
 
body { 
    text-align: center; 
    } 
 
div { 
    display: table; 
    height: 100%; 
    margin: 0 auto; 
    vertical-align: middle; 
    } 
 
div div { 
    display: table-cell; 
    } 
 
div div p { 
    padding: 10px; 
    border: ridge black; 
 
/*]]>*/ 
</style> 
</head> 
 
<body> 
<div><div> 
<p>If you aren't sent to the page, click this link.<br /> [<a 
href="<? echo $where ?>"> Send me on </a>].</p> 
</div></div> 
</body> 
</html>


H: Compare code to this. If still a prob, we'll look at your exact source.

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

Howard
Offline
Regular
Last seen: 17 years 18 weeks ago
Joined: 2005-07-29
Posts: 14
Points: 0

Why aren't my first drop-down box's links working?

Hi. I'm still trying to absorb the new code you posted.

I have a question about this code segment: \"" . $where . "\"
What exactly is going on in it? What's each component for?

Also, in PHP is "legend" the same as title in HTML?

Howard

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 1 year 38 weeks ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9776
Points: 3858

Why aren't my first drop-down box's links working?

<? echo "If you aren't sent to the page, click this link,
  <a href=\"" . $where . "\">Send me on</a>" ?>

Everything between the <? and ?> is seen by the server as being PHP and is run through the PHP interpreter. The syntax for echo is <? echo "hello world" ?> So, if you need a quote within the literal part,"to", it must be escaped, \". The '.', dot, is the concatenation symbol, much as '+' is in javascript.

I greatly simplified it in the later version.

<p>If you aren't sent to the page, click this link.<br /> [<a
href="<? echo $where ?>"> Send me on </a>].</p> 

In this version, only the value of the variable is echoed by the interpreter.

One of the beauties of PHP is the ability to slip in and out of the interpreter on the fly.

<legend> is an html element that belongs to <fieldset>.

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.