Solved

Dynamic Link to Change Textbox Content

Posted on 2008-10-31
12
277 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
This article discusses four methods for overlaying images in a container on a web page
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 viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now