Solved

Dynamic Link to Change Textbox Content

Posted on 2008-10-31
12
280 Views
Last Modified: 2012-05-05
I would like to create a simple function that would, on the click of a link (or recordset of links), would change the content of a textbox without reloading  the page. Is there anyway to do this; perhaps, via javascript? I would prefer not to use AJAX in this application. Thank you.
0
Comment
Question by:EMB01
  • 6
  • 4
  • 2
12 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 22850142
>>or recordset of links
What do you mean?
0
 
LVL 14

Author Comment

by:EMB01
ID: 22850166
The links will be fed by a recordset of search results. These results, when clicked, should modify the content of the textbox without reloading the page. Is this feasible?
0
 
LVL 7

Accepted Solution

by:
bluV11t earned 500 total points
ID: 22850189
Try:

In head tag place this javascript function:

          <script language=javascript>
          function fnUpdateText(myTextID, myNewText){
              document.getElementById(myTextID).value = myNewText;
          }
       </script>

   <a href="#" onclick="JavaScript: fnUpdateText('myFirstInputBox', 'This is my new text')">Update text 1</a><br />
   <a href="#" onclick="JavaScript: fnUpdateText('myFirstTB', 'This is my new text')">Update text 2</a><br /><br />
   Text 1 <input type="text" id="myFirstInputBox" value="Old contents" /><br />
   Text 2 <textarea rows=5 cols=20 id="myFirstTB">My old contents</textarea>
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 7

Expert Comment

by:bluV11t
ID: 22850198
This (of course) goes in the body tag:

   <a href="#" onclick="JavaScript: fnUpdateText('myFirstInputBox', 'This is my new text')">Update text 1</a><br />
   <a href="#" onclick="JavaScript: fnUpdateText('myFirstTB', 'This is my new text')">Update text 2</a><br /><br />
   Text 1 <input type="text" id="myFirstInputBox" value="Old contents" /><br />
   Text 2 <textarea rows=5 cols=20 id="myFirstTB">My old contents</textarea>
0
 
LVL 14

Author Comment

by:EMB01
ID: 22850338
Oh, that's quite simple then... and easy to understand! One more question, though; and I can post a new question if you want - but - would it be difficult to have the links on one page, then deliver the updated text on another? Or, would that be too difficult?
0
 
LVL 14

Author Comment

by:EMB01
ID: 22850789
My guess is, you can't update the contents of one page from another without reloading. Not sure though... Anyway, here's the points!
0
 
LVL 14

Author Closing Comment

by:EMB01
ID: 31512039
Thanks a bunch.
0
 
LVL 82

Expert Comment

by:hielo
ID: 22850828
you can have a hidden frame and pass the text to the other page via the frame's url:

<script language=javascript>
          function fnUpdateText(myTextID, myNewText){
              document.getElementById(myTextID).value = myNewText;
 document.getElementById("hiddenFrame").src="otherPage.php?updatedText=" + encodeURIComponent(myNewText);
          }
       </script
<iframe src="#" id="hiddenFrame" name="hiddenFrame" style="position:absolute;left:-100em;"></iframe>

Open in new window

0
 
LVL 82

Expert Comment

by:hielo
ID: 22850834
Ouch!!
0
 
LVL 14

Author Comment

by:EMB01
ID: 22850897
Sorry, I didn't figure anyone else would be responding! I don't really want an iFrame in there, anyway. Perhaps, I'll post a new question on "Modifying a textbox from another page," or something like that...
0
 
LVL 82

Expert Comment

by:hielo
ID: 22851063
So you want no frames, no ajax, no page reloading. I a popup OK?
0
 
LVL 14

Author Comment

by:EMB01
ID: 22851152
Yeah, actually, I'd love a popup! I sort of assumed that was AJAX, though.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question