View Full Version : JavaScript to clear & load the TextBox contents.

01-20-2009, 07:34 PM
I want to have this feature implemented in my application.
That is: I have 2 frames in one HTML page. In frame1, there is a Button. In frame2, there is a Textbox.
Now, if i click on the button in frame1, then the textbox in frame2 should load some text and again if i click on the same button, the content in the textbox should get clear.
Could anyone pls tell me how to go with it....????
will appreciate if code is available.

01-20-2009, 08:01 PM
Are you using framesets or iframes? Either way is possible if both frames (and the parent page) all lie in the same domain. However if you're using framesets I'd have to ask why.

01-20-2009, 08:19 PM
yes, i am using framesets. pls find the code below..it is working. but not able to clear the contents of the textbox, using the same button. pls have a look.

<script language="JavaScript">
function passText(str) {
top.frames['right'].document.yourform.msg.value = str;

<frameset cols="300,*">
<frame name="left" src="pass-textbox-framesl.html">
<frame name="right" src="pass-textbox-framesr.html">

<html><body><center><form name=myform>
<input type=button value="show text" onClick="parent.passText('vick');">

<form name=yourform>
<input type=text id=tb name=msg size=10 value="">

01-20-2009, 09:05 PM
add this to pass-textbox-framesl.html:

<input type=button value="clear text" onClick="parent.passText('');" />

01-21-2009, 06:34 AM
But i need to have only single button to show and also to clear the textbox content.
I mean, the button should do some toggle action.
how to do?

01-21-2009, 03:09 PM
Replace passText with this:

function toggleText(btn,str)
var input = top.frames['right'].document.yourform.msg;
input.tog = !input.tog;
input.value = input.tog ? str : "";
btn.value = input.tog ? "Toggle Off" : "Toggle On";

Replace your button with this:

<input type="button" value="Toggle On" onclick="parent.toggleText(this,'vick')" />

01-21-2009, 05:03 PM
hay, its giving error. am running the page in Firefox browser. pls find the log.

top.frames.right.forms is undefined
toggleText(input Toggle On, "vick") FRAMESET.html (line 9)

var input = top.frames["right"].forms["yourform"].msg;

let me know wht to modify.

01-21-2009, 07:29 PM
See the red in my previous post.

You should probably try and learn some JS/XHTML yourself so you don't run in to these problems in the future.