473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Needing hyperlinks inside of textbox

2
Hi! I recently started adding Javascript to my html pages and I am learning it as fast as I can. I am very stuck right now, though. I have a dropdown list that has all the volenteer opportunities listed. When they pick something, a corresponding paragraph is written into a textarea. Well, I apparently can't put hyperlinks or formatted text into a textarea, and I really need them. I read about Document.write, which WILL do formatted text, but when I used onchange="document.write(shortcut.text.value)" instead of onchange="showtext()" it goes off to another window or something and writes it there. Putting the document.write statement by itself after the select box works one time, but won't change if they select something else from the drop-down list.

Is there some way to have different formatted, hyperlinked paragraphs appear and change each time they select something different from a drop-down list?

Just sign me,
Baffled and Stuck,
-Susan

<form name="combowithtext">
<select name="example" size="1" onchange="showtext()">
<option>Book Sales
</option><option>Build Team
</option><option>Bus Ministry/Drivers
</option><option>Drama Ministry
</option></select>
<br>
<textarea rows="5" cols="21" wrap="virtual" name="text"></textarea>


<script language="javascript">
<!--
var shortcut=document.combowithtext
var descriptions=new Array()
//extend this list if neccessary to accomodate more selections
descriptions[0]="Assist with book sales and inventory."
descriptions[1]="Assist with carpentry, painting and set design"
descriptions[2]="Drive or monitor on bus routes"
descriptions[3]="Communicate the message through drama productions, commercials, skits and human videos"

shortcut.text.value=descriptions[shortcut.example.selectedIndex]

function showtext(){
shortcut.text.value=descriptions[shortcut.example.selectedIndex]
;
}
//-->
Dec 20 '06 #1
3 3172
b1randon
171 Expert 100+
Hi! I recently started adding Javascript to my html pages and I am learning it as fast as I can. I am very stuck right now, though. I have a dropdown list that has all the volenteer opportunities listed. When they pick something, a corresponding paragraph is written into a textarea. Well, I apparently can't put hyperlinks or formatted text into a textarea, and I really need them. I read about Document.write, which WILL do formatted text, but when I used onchange="document.write(shortcut.text.value)" instead of onchange="showtext()" it goes off to another window or something and writes it there. Putting the document.write statement by itself after the select box works one time, but won't change if they select something else from the drop-down list.

Is there some way to have different formatted, hyperlinked paragraphs appear and change each time they select something different from a drop-down list?

Just sign me,
Baffled and Stuck,
-Susan

<form name="combowithtext">
<select name="example" size="1" onchange="showtext()">
<option>Book Sales
</option><option>Build Team
</option><option>Bus Ministry/Drivers
</option><option>Drama Ministry
</option></select>
<br>
<textarea rows="5" cols="21" wrap="virtual" name="text"></textarea>


<script language="javascript">
<!--
var shortcut=document.combowithtext
var descriptions=new Array()
//extend this list if neccessary to accomodate more selections
descriptions[0]="Assist with book sales and inventory."
descriptions[1]="Assist with carpentry, painting and set design"
descriptions[2]="Drive or monitor on bus routes"
descriptions[3]="Communicate the message through drama productions, commercials, skits and human videos"

shortcut.text.value=descriptions[shortcut.example.selectedIndex]

function showtext(){
shortcut.text.value=descriptions[shortcut.example.selectedIndex]
;
}
//-->
Susan, you don't want to use document.write() or a textarea. The reason is that document.write() rewrites the source of the window. Textareas also display only simple text, and links are html. You seem like you're learning fast though so I'm going to give you a few tips and some reference material and I'm sure you'll complete your project.

Instead of using textarea use a div tag. Div is just an invisible "division" of a web page that holds some HTML. It will look like this:

Expand|Select|Wrap|Line Numbers
  1. <div id="linksHere"></div>
  2.  
When you want to write HTML to the inside of this div you'll do some code like this:

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. document.getElementById('linksHere').innerHTML = "<a href=\"http://www.google.com\">Google</a>";
  3. </script>
  4.  
Simple enough? Here's some more about div tags and also more about using .innerHTML. Post again if you get hung up but you seem like you just needed a push in the right direction.
Dec 21 '06 #2
sueboo
2
Wow! Thank you so much for pointing me in the right direction! I found a script that ALMOST does what I want, exept they use an unordered list instead of a select box. But I can't seem to put <a href="javascript:rollerCoster(1);"> around the <option> of the select box. How would I apply the rollerCoaster script to the selected item of a Select box?
Thanks,
-Susan

function rollerCoster(id) {
var txts = new Array(6);//Make a few Jokes - Ha Ha Ha
txts[0] = Doctor, Doctor I'm a burglar!<br />Have you taken anything for it?br />";
txts[1] = Engineers ;
txts[2] = " Four hundred and seventy one ;
document.getElementById("jokearea").innerHTML = txts[id];
}

<div id="jokearea">&nbsp;</div>
<ul>
<li><a href="javascript:rollerCoster(0);">Doctor</a></li>
<li><a href="javascript:rollerCoster(1);">Mathamatics</a></li>
<li><a href="javascript:rollerCoster(2);">Light Bulb</a></li>
</ul>

<div id="jokearea">&nbsp;</div>


Susan, you don't want to use document.write() or a textarea. The reason is that document.write() rewrites the source of the window. Textareas also display only simple text, and links are html. You seem like you're learning fast though so I'm going to give you a few tips and some reference material and I'm sure you'll complete your project.

Instead of using textarea use a div tag. Div is just an invisible "division" of a web page that holds some HTML. It will look like this:

Expand|Select|Wrap|Line Numbers
  1. <div id="linksHere"></div>
  2.  
When you want to write HTML to the inside of this div you'll do some code like this:

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. document.getElementById('linksHere').innerHTML = "<a href=\"http://www.google.com\">Google</a>";
  3. </script>
  4.  
Simple enough? Here's some more about div tags and also more about using .innerHTML. Post again if you get hung up but you seem like you just needed a push in the right direction.
Dec 22 '06 #3
b1randon
171 Expert 100+
Wow! Thank you so much for pointing me in the right direction! I found a script that ALMOST does what I want, exept they use an unordered list instead of a select box. But I can't seem to put <a href="javascript:rollerCoster(1);"> around the <option> of the select box. How would I apply the rollerCoaster script to the selected item of a Select box?
Thanks,
-Susan

function rollerCoster(id) {
var txts = new Array(6);//Make a few Jokes - Ha Ha Ha
txts[0] = Doctor, Doctor I'm a burglar!<br />Have you taken anything for it?br />";
txts[1] = Engineers ;
txts[2] = " Four hundred and seventy one ;
document.getElementById("jokearea").innerHTML = txts[id];
}

<div id="jokearea">&nbsp;</div>
<ul>
<li><a href="javascript:rollerCoster(0);">Doctor</a></li>
<li><a href="javascript:rollerCoster(1);">Mathamatics</a></li>
<li><a href="javascript:rollerCoster(2);">Light Bulb</a></li>
</ul>

<div id="jokearea">&nbsp;</div>
That's because you don't really want a link (<a>) what you want to do is to run your script when the selection changes. You do this with the OnChange event handler. If you need to call rollerCoaster with the index of the item that is selected you'll need to use the SelectedIndex property of the select box. The code will look something like this:
Expand|Select|Wrap|Line Numbers
  1. <select onChange="javascript:rollerCoaster(this.selectedIndex);">
  2.  
That should help. Let me know if you're still having trouble.
Dec 22 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: c_kubie | last post by:
I have a listbox that has several hyperlinks I am displaying the contents using =listbox.column(1) The link is displayed correctly in the table but if dispayed in a textbox, it will show up...
1
by: John | last post by:
Hi all, My app contains a datagrid with hyperlinks inside and these hyperlinks all point back to the same page. The problem is that I have a 'search' user control and the viewstate changes once...
2
by: Scott Kelley | last post by:
I have a control inside of an asp:Table control. Once I place it in there, I can't seem to edit it any more (Double click to add events, drag to reposition, etc...). If I use an HTML table, no...
0
by: John Shum | last post by:
I prepare a UserControl that act as a lookup control, once the code is enter in the TextBox, the description will appear in another TextBox outside the UserControl of the same row in a DataGrid via...
2
by: Lauren Wilson | last post by:
Any advice on this would be most appreciated. Using VBA code in Access 2003, is there a way to insert a fully functional hyperlink inside of an Office Assistant help bubble? Thanks folks, ...
2
by: John R. Lewis | last post by:
I posted this yesterday with a different email address. I am reposting with my fake-address as given to me by Microsoft so that I can be guraranteed a response from a support representative. Sorry...
0
by: cscan | last post by:
Hi all, I write 2 controls. (Acutally I simplifed my project here) MyTextBox and MyPanel. MyPanel contains a property which is a collection of MyTextBox. public partial class MyPanel :...
2
by: Nathan | last post by:
I'm trying to use a LocalReport in a ReportViewer and make a couple fields in the report show up as hyperlinks so I can navigate to other pages after running the report. The hyperlinks themselves...
1
by: Øyvind Isaksen | last post by:
I need to know how to handle controls inside a repeater, how to send and recieve data from another page to one spesific control inside a repeater. Clue: I have a repeater that dynamicly lists...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.