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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing to a text box from a prompt???

    I am trying to write a script that will pass information from a prompt to a text field (similarly to when you click bold or another button on this forum). I have it (kind of) working with a custom window with a form in but i would prefer to use a prompt. I also have the following problems:

    • I cant get it to pass the text to the text field AND close the window, only one of them
    • If there is allready anything in the text box on the main page already, it replaces it rather than adding the text from the prompt at the end


    I am a newbie at all this and im finding it pretty confusing!!

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Can you post what you've got?

  • #3
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No problems, this is what I have:

    This is in the head of the document:
    Code:
    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function explain(name, output, msg) {
    newwin = window.open('','','top=150,left=150,width=325,height=300');
    if (!newwin.opener) newwin.opener = self;
    with (newwin.document)
    {
    open();
    write('<html>');
    write('<body onLoad="document.form.box.focus()"><form name=form>' + msg + '<br>');
    write('<p>You may enter your ' + name + ' here and it will be copied into the form for you.');
    write('<p><center>' + name + ':  <input type=text name=box size=10>');
    write('<p><input type=button value=Close onClick=' + output + '=box.value onClick=window.close()>');
    write('</center></form></body></html>');
    close();
       }
    }
    //  End -->
    </script>
    And this is in the body:

    Code:
    <form name=form method=post action="/cgi-bin/your-script.cgi"> 
    
    User Name:  <input type=text name="username" size=10>  <a href="javascript:explain('User Name', 'opener.document.form.username.value', 'The user name field is where you select a user name that you will use every time you access this site.  Pick something you can easily remember and that will easily identify you.');" onMouseOver="window.status='Click for explanation...';return true;" onMouseOut="window.status='';return true;">Help?</a>
    
    <br>
    Password:  <input type=text name="password" size=10>  <a href="javascript:explain('Password', 'opener.document.form.password.value', 'The password field is where you select a unique password for your account.  This password will be required each time you login to the site.  For security purposes, be sure to pick a password that you can easily remember that contains letters and numbers or symbols but would be hard for others to guess.');" onMouseOver="window.status='Click for explanation...';return true;" onMouseOut="window.status='';return true;">Help?</a>
    
    </form>
    Any ideas

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Why do you need the prompt when the field is already in the main page? And also, if you use prompt for password, the input would be visible and not displayed as *. You should use input type="password" so that the input is displayed as *

  • #5
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    its not actually for a password, that was just some code from a book that i was starting with.

    The reason i wanted it was for the same reason these forums use pop ups

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 250 Times in 246 Posts
    This?
    Code:
    <script type="text/javascript">
    function addText(fld){
      var txt = prompt("Enter text to add:","");
      if (txt){
        fld.value += txt;
      }
    }
    </script>
    ...
    <textarea name="msg"></textarea>
    <input type="button" value="Add" onclick="addText(this.form.msg)" />
    
    <textarea name="msg2"></textarea>
    <input type="button" value="Add" onclick="addText(this.form.msg2)" />

  • #7
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this doesnt seem to do anything, just shows an error at the bottom of the page when i click the button??

  • #8
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually i've just realised where I needed to add my form name to it.
    Thanks Glenngv thats exactly what i needed

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Glad to help you. BTW, welcome to CF Forums.


  •  

    Posting Permissions

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