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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to create dynamic link based on the field selected from menu

Status
Not open for further replies.

920506

Programmer
Jun 13, 2003
201
US
Hi,
I need to create a text link dynamically. when users choose a category from option menu, the text link on the web page will link to the different content. I have several dynamic things happen at the same time based on the
value of the field.
thanks
Betty
 
Hi,
I did the following, but the problem is that when I change the option value, you have to click refresh button, in order for the link changed, anybody can fix that?
thanks
Betty



<body onload="start()">
<p>A drop down Deductible Menu</p>
<form method="POST" name="SendMe" >
<p>Deductible<select name="DropIt" size="1" onChange="start()" >
<option value="250"> $250 </option>
<option value="1000" selected> $1000</option>
<option value="1500"> $1500 </option>
<option value="2000"> $2000 </option>
</select> </p>

<p></p>
<p><div id="Coverage"></div></p>
<script language="JavaScript">
var v=document.SendMe.DropIt[document.SendMe.DropIt.selectedIndex].value;
if (v==1000) { output1="<a href=' output1 +="Coverage";
output1 +="</a>"
document.getElementById("Coverage").innerHTML=output1;
document.getElementById("Coverage").href=" }
if (v==250) { output1="<a href=' output1 +="Coverage";
output1 +="</a>"
document.getElementById("Coverage").innerHTML=output1;
document.getElementById("Coverage").href=" }
</script>
 
According to the snippet,
Code:
onload="start()"
Code:
onChange="start()"
there should be a function start() inside the script. Another,
Code:
 var v=document.SendMe.DropIt[document.SendMe.DropIt.selectedIndex].value;
can be replace by
Code:
 var v=document.SendMe.DropIt.value;
Hope the following modification helps,
Code:
<body onload="start()">
<p>A drop down Deductible Menu</p>
 <form method="POST" name="SendMe" >
    <p>Deductible<select name="DropIt" size="1" onChange="start()" >
        <option value="250">  $250 </option>
        <option value="1000" selected> $1000</option>
        <option value="1500"> $1500 </option>
        <option value="2000"> $2000 </option>
    </select> </p>
    
 <p></p>
    <p><div id="Coverage"></div></p> 

<script language="JavaScript">
[COLOR=orange]function start() {
  var v=document.SendMe.DropIt.value;[/color]
  if (v==1000)      { output1="<a href='[URL unfurl="true"]http://www.yahoo.com'>";[/URL]
                          output1 +="Coverage";
                        output1 +="</a>"
                    document.getElementById("Coverage").innerHTML=output1;
                  document.getElementById("Coverage").href="[URL unfurl="true"]http://www.yahoo.com";[/URL]
                  }
  if (v==250)            { output1="<a href='[URL unfurl="true"]http://www.google.com'>";[/URL]
                          output1 +="Coverage";
                        output1 +="</a>"
                    document.getElementById("Coverage").innerHTML=output1;
                  document.getElementById("Coverage").href="[URL unfurl="true"]http://www.google.com";[/URL]
                  }
[COLOR=orange] }[/color]
</script>
 
i made a small code, try it:
Code:
<html>
<script>
function start(TheValue)
{
	document.getElementById("TheLink").href=TheValue
	document.getElementById("TheLink").innerText=TheValue
}
</script>
<form method="POST" name="SendMe" >
    <p>Deductible<select name="DropIt" size="1" onChange="start(this.value)" >
        <option value="250">  $250 </option>
        <option value="1000" selected> $1000</option>
        <option value="1500"> $1500 </option>
        <option value="2000"> $2000 </option>
    </select> </p>
   <br>
<a href="#" id='TheLink'></a>
</form>
</html>

Known is handfull, Unknown is worldfull
 
thank you both, 13sio and vbkris.
13 sio, you really made a good point.
Betty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top