Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

embed a link in a select field

Status
Not open for further replies.

edpatterson

IS-IT--Management
Feb 24, 2005
186
0
0
I am trying to duplicate the Nutrition Facts label using HTML. I have the basic layout covered and now want to be able to add a new unit of measure of it is not listed.
I have
Code:
<tr><td>Serving Size</td>
  <td><input type='text' name='servingCount'></td>
  <td>
    <select name='servingName'>
      <option value='Each'>Each</option>
      <option value='Bun'>Bun</option>
      <option value='Link'>Link</option>
      <option value='new'><a href="./newServingName.php">...new...</a></option>
    </select>
  </td>
  <td><input type='text' name='metricCount'></td>
  <td><select name='metricName'> <option value='gram'>g</option><option value='mL'>mL</option></select></td>
</tr>
the ...new... shows up but not as a link.

Is it possible to embed a link in a select field?
 
So, it is not possible without javascript? I do not know beans about javascript.
 
So, it is not possible without javascript? I do not know beans about javascript.

:)

Put this in the <head></head> section of your webpage:

Code:
<script language="javascript" type="text/javascript">
	function openNew(strValue) {
		if (strValue.toUpperCase() == "NEW") {
			document.location.href = "./newServingName.php";
		} else {
			return;
		}
	}
</script>

Change your select box to read like this:

Code:
<select name='servingName' [b]onchange='openNew(this.value);'[/b]>

change your last option and get rid of the link tag

Code:
<option value='new'>...new...</option>

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
crude but easy way:
Code:
<select name='servingName' [COLOR=red]onchange="window.location='yourLink'+this.value+'.html';"[/color]>
  <option value='Each'>Each</option>
  <option value='Bun'>Bun</option>
  <option value='Link'>Link</option>
</select>

or if using the querystring:

Code:
<select name='servingName' [COLOR=red]onchange="window.location='yourLink.php?thisVar='+this.value;"[/color]>
  <option value='Each'>Each</option>
  <option value='Bun'>Bun</option>
  <option value='Link'>Link</option>
</select>

________________________________
Top 10 reasons to procrastinate:
1)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top