Solved

Dynamic Link to Change Textbox Content

Posted on 2008-10-31
12
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

756 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