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!

click on text to show that text in a text box 1

Status
Not open for further replies.

PNorman

Programmer
Feb 7, 2005
30
0
0
US
I'm going nuts trying to find this. I'm not the most advanced web developer by far....and I guess this proves it. I thought for sure I'd find the answer in either VBScript or Javascript but no luck!

In my web page all I want to do is click on some text and have that text appear in a text box. That's it!

Thanks for your help
 
What do you mean by 'click on some text'?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Here's the link...

After logging in I have a couple more text boxes for entering music one of which is titled Artist. I want to be able to click on any of the artists listed on the left of the page and have that artist appear in the appropriate text box where I would be entering the Artist. This will save me time when entering multiple CDs by the same artist.
 
[1] You should not repeat every place the HideDisplay(elementid.) That's very clumsy. You may as well find cross-browser issue as you refer the element simply by its id. (By such referring, you may restrict your audience to ie-based browser.) You better solution would be to make a class (like you've done for DBPage, but now call it some name like initHide.
[tt].initHide {display:none;}[/tt]
Then for each element with id like CD_TreeView1Btn etc, give it an attribute class="initHide".

[2] As to the question to display the clicked text to a text box, you need to wrap the text with the span tag and give it an onclick handler. The handler should send the innerHTML to the text box as its value.

A demo of both of these can be done like this.
Code:
<html>
<head>
<style type="text/css">
.initHide {display:none;}
.initShow {display:block;}	/* for testing */
</style>
<script language="javascript">
function postdata(obj) {
	document.getElementById("x").value=obj.innerHTML;
}
</script>
<script language="vbscript">
sub postdata_vbs(obj)
	document.getElementById("x").value=obj.innerHTML
end sub
</script>
</head>
<body>
<p><span onclick="postdata(this)">Fandango</span></p>
<p><span onclick="vbscript:postdata_vbs(me)">Greatest Hits</span></p>
<input id="x" type="text" />
<p class="initHide">This is a hidden paragraph.</p>
<p class="initShow">This is a displayed paragraph.</p>
</body>
</html>
- tsuji
 
tsuji,

Thanks for the reply and advice. I'll try the hide stuff after I get the onclick to work.

The code you have works but not for a list of text such as what I have. Each Artist is displayed from a loop so I guess the routine is called but it doesn't understand which text is being displayed....I think.

I've tried adding an id but it didn't work...for all I know I did it wrong. Any more advice?

thanks again.
 
>Each Artist is displayed from a loop so I guess the routine is called but it doesn't understand which text is being displayed

I've to quote myself "wrap the text with the span tag and give it an onclick handler'.

The way I showed you is well suited for the case when it is generated by a loop or a routine. Simply wrap the _text_ with span-tag, the text "a" replaced by <span onclick="thehandler(this)">a</span>. The handler part is in a generic form independent of the text (a). As to where to post to, I have no idea what you're doing and what form actually is. Hence, the destination part is what you have to put some more effort in because there is no where in the page provisioned for this part.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top