Solved

Dynamic Link to Change Textbox Content

Posted on 2008-10-31
12
283 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

Suggested Solutions

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

738 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