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

Link Generator 1

Status
Not open for further replies.

apex82

Programmer
Mar 2, 2009
127
GB
I have a form that generates a link.

A user selects an option from a dropdown menu then via a javascript function a link is created in a textarea box.

I would like to add a text box to the form so a user has an option to add their own text if they don’t want to use the dropdown menu.

Here is the form code:

Code:
<form name="linkForm">
  <input type="hidden" name="url" value="<%= str_address %>" />
  <input type="hidden" name="name" value="Test" />
  <input type="hidden" name="target" value="_blank" />

    <select name="display" onChange="MakeLink()">
      <option value="<%= str_Name_A %>"><%= str_Name_A %></option>
      <option value="<%= str_Name_B %>"><%= str_Name_B %></option>
      <option value="<%= str_Name_C %>"><%= str_Name_C %></option>
      <option value="<%= str_Name_D %>"><%= str_Name_D %></option>
    </select>
    <br>
    <br>
    <textarea rows="3" cols="70" name="output" id="output" onClick="SelectAll('output');"></textarea>
</form>

Javascript Function:

Code:
function MakeLink() {
	var url = FormField("url");
	var display = FormField("display");
	var target = FormField("target");
	var name = FormField("name");
	
	var linkstr = "<a href=\"" + url + "\"";
	if (name.length > 0) {
		linkstr += " name=\"" + name + "\"";
	}
	linkstr += " target=\"" + target + "\">" + display + "</a>";
	document.linkForm.output.value = linkstr;
	document.linkForm.output.focus();
}


I can't seem to find a example anywhere on the net.

Is this possible?

Thanks.
 
yes, instead of using the var display = FormField("display");
form the select box, check to see that the text box has been filled in and if i has use that in your generator:

HTML:
<input type="text" name="mytext">

Code:
var mytext=FormField("mytext");
if(mytext!=""){
var display=mytext;
}
else{
var display = FormField("display");
}

and JS questions should be asked in forum216





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top