View Full Version : Passing to a text box from a prompt???

07-12-2005, 09:45 AM
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!! :confused:

07-12-2005, 10:32 AM
Can you post what you've got?

07-12-2005, 10:45 AM
No problems, this is what I have:

This is in the head of the document:

<!-- 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)
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()>');
// End -->

And this is in the body:

<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>

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>


Any ideas

07-12-2005, 12:05 PM
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 *

07-12-2005, 12:17 PM
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

07-12-2005, 12:38 PM

<script type="text/javascript">
function addText(fld){
var txt = prompt("Enter text to add:","");
if (txt){
fld.value += txt;
<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)" />

07-13-2005, 04:34 PM
this doesnt seem to do anything, just shows an error at the bottom of the page when i click the button??

07-13-2005, 04:41 PM
Actually i've just realised where I needed to add my form name to it.
Thanks Glenngv thats exactly what i needed :thumbsup:

07-15-2005, 04:16 AM
Glad to help you. BTW, welcome to CF Forums. :)