Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Nov 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScript to clear & load the TextBox contents.

    Hi,
    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.

  • #2
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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.
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • #3
    New Coder
    Join Date
    Nov 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

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

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


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

    pass-textbox-framesr.html
    <html><body>
    <form name=yourform>
    <input type=text id=tb name=msg size=10 value="">
    </form>
    </body></html>

  • #4
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    add this to pass-textbox-framesl.html:
    Code:
    <input type=button value="clear text" onClick="parent.passText('');" />
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • #5
    New Coder
    Join Date
    Nov 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks.
    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?

  • #6
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    Replace passText with this:
    Code:
    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:
    Code:
    <input type="button" value="Toggle On" onclick="parent.toggleText(this,'vick')" />
    Last edited by itsallkizza; 01-21-2009 at 08:28 PM.
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • #7
    New Coder
    Join Date
    Nov 2008
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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.
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •