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
Solved

Dynamic Link to Change Textbox Content

Posted on 2008-10-31
12
281 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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Html value of radio 14 27
JQuery Syntax... 4 29
Ajax and PHP 4 29
How to control cache of some js files ? 7 37
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

790 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