By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,607 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,607 IT Pros & Developers. It's quick & easy.

returning value from prompt() ??

P: n/a
JSE
Hello everyone. here's what we have in an html file.

<form .....

<input type=button name="comment" onclick=" prompt('enter comment','
' )" >

Is there anyway to get the value returned from the prompt in the statement
above, into the value of the statement below ?

<input type=hidden name="comment_text" value = ???? >
We would like the user to click the "comment" button, have another window
popup where they enter their comment, and then take the comment text and
append it to the value parameter of the hidden statement.

Is it possible?

Thanks very much.

John Edgar
Jul 20 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Ivo
"JSE" <jo**@nospam.conwayinfo.ca> wrote in message
news:ayu%b.621790$X%5.448756@pd7tw2no...
Hello everyone. here's what we have in an html file.

<form .....

<input type=button name="comment" onclick=" prompt('enter comment',' ' )" >
You need to store the return of the prompt in a variable or do something
with it immediately, otherwise the return value gets lost.
prompt('Hello',''); is useless.
p=prompt('Hello',''); saves whatever user types into variable p for further
processing.
<input type=hidden name="comment_text" value = ???? >

We would like the user to click the "comment" button, have another window
popup where they enter their comment, and then take the comment text and
append it to the value parameter of the hidden statement.


Rewrite the button as follows:
<input type="button" name="comment"
onclick=" var p = prompt('enter comment',''); if (p) this.form.comment_text
+= p; ">

If you want to do some checking on p first (or really want a window instead
of a silly prompt), it is perhaps better to take the whole code out of the
onclick into a separate function.
HTH
Ivo

Jul 20 '05 #2

P: n/a
JSE wrote:
Hello everyone. here's what we have in an html file.

<form .....

<input type=button name="comment" onclick=" prompt('enter comment','
' )" >

Is there anyway to get the value returned from the prompt in the statement
above, into the value of the statement below ?

<input type=hidden name="comment_text" value = ???? >
We would like the user to click the "comment" button, have another window
popup where they enter their comment, and then take the comment text and
append it to the value parameter of the hidden statement.

Is it possible?

Thanks very much.

John Edgar


<input type="button" name="comment" onclick="comment_text.value=
prompt('enter comment')">

Mick


Jul 20 '05 #3

P: n/a
Lee
JSE said:

Hello everyone. here's what we have in an html file.

<form .....

<input type=button name="comment" onclick=" prompt('enter comment','
' )" >

Is there anyway to get the value returned from the prompt in the statement
above, into the value of the statement below ?

<input type=hidden name="comment_text" value = ???? >
We would like the user to click the "comment" button, have another window
popup where they enter their comment, and then take the comment text and
append it to the value parameter of the hidden statement.


onclick="this.form.comment_text.value=prompt('ente r comment')"

Jul 20 '05 #4

P: n/a
On Thu, 26 Feb 2004 23:17:22 GMT, Mick White
<mw******@BOGUSrochester.rr.com> wrote:
<input type="button" name="comment"
onclick="comment_text.value=prompt('enter comment')">


And if I'm not using IE or Opera?

Try:

document.formName.elementName.value = prompt('text');

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #5

P: n/a
Michael Winter wrote:
On Thu, 26 Feb 2004 23:17:22 GMT, Mick White
<mw******@BOGUSrochester.rr.com> wrote:
<input type="button" name="comment"
onclick="comment_text.value=prompt('enter comment')">

And if I'm not using IE or Opera?

Try:

document.formName.elementName.value = prompt('text');

Mike

A reference to a sibling element should not need to reference its
containing form, I would prefer "this.form"

Mick
Jul 20 '05 #6

P: n/a
On Fri, 27 Feb 2004 01:04:21 GMT, Mick White
<mw******@BOGUSrochester.rr.com> wrote:
Michael Winter wrote:
On Thu, 26 Feb 2004 23:17:22 GMT, Mick White
<mw******@BOGUSrochester.rr.com> wrote:
<input type="button" name="comment"
onclick="comment_text.value=prompt('enter comment')">


And if I'm not using IE or Opera?

Try:

document.formName.elementName.value = prompt('text');

Mike


A reference to a sibling element should not need to reference its
containing form, I would prefer "this.form"


That is what I would use normally, too. Why didn't you just suggest that
in the first place?

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #7

P: n/a
Thank you, everyone, for your very quick responses. I appreciate it.
John.

"JSE" <jo**@nospam.conwayinfo.ca> wrote in message
news:ayu%b.621790$X%5.448756@pd7tw2no...
Hello everyone. here's what we have in an html file.

<form .....

<input type=button name="comment" onclick=" prompt('enter comment',' ' )" >

Is there anyway to get the value returned from the prompt in the statement above, into the value of the statement below ?

<input type=hidden name="comment_text" value = ???? >
We would like the user to click the "comment" button, have another window popup where they enter their comment, and then take the comment text and append it to the value parameter of the hidden statement.

Is it possible?

Thanks very much.

John Edgar

Jul 20 '05 #8

P: n/a
Michael Winter wrote:
On Fri, 27 Feb 2004 01:04:21 GMT, Mick White
<mw******@BOGUSrochester.rr.com> wrote:
Michael Winter wrote:
On Thu, 26 Feb 2004 23:17:22 GMT, Mick White
<mw******@BOGUSrochester.rr.com> wrote:

<input type="button" name="comment"
onclick="comment_text.value=prompt('enter comment')">
And if I'm not using IE or Opera?

Try:

document.formName.elementName.value = prompt('text');

Mike

A reference to a sibling element should not need to reference its
containing form, I would prefer "this.form"

That is what I would use normally, too. Why didn't you just suggest that
in the first place?

Mike


I did, see above.
Mick
Jul 20 '05 #9

P: n/a
Mick White wrote:
Michael Winter wrote:
Mick White wrote:
Michael Winter wrote:
Mick White wrote:
> <input type="button" name="comment"
> onclick="comment_text.value=prompt('enter comment')"> ^^^^^^^^^^^^
And if I'm not using IE or Opera?
It will also work with Mozilla/Gecko because of the custom scope chain
added to event handling functions generated from attribute code. There
are still a number of other browsers on which it is guaranteed to fail
because they provide no similar mechanism.
document.formName.elementName.value = prompt('text');

A reference to a sibling element should not need to reference
its containing form, I would prefer "this.form"


That is what I would use normally, too. Why didn't you just suggest
that in the first place?


I did, see above.


this.form - does not appear in the code above or in any of your
preceding posts to this thread.

Richard.
Jul 20 '05 #10

P: n/a


Mick White wrote:
[snip]
\>>>>A reference to a sibling element should not need to reference
its containing form, I would prefer "this.form"


[snip]

A reference to a sibling element should not need to reference
its containing form, I would prefer "this.form"
Mick
Jul 20 '05 #11

P: n/a
Mick White wrote:
Mick White wrote:
[snip]
>A reference to a sibling element should not need to reference
>its containing form, I would prefer "this.form"

[snip]

A reference to a sibling element should not need to reference
its containing form, I would prefer "this.form"


Your assertion that "I did" in response to the question "Why didn't you
just suggest that in the first place?" implies that you did mention -
this.form - in a post preceding the one that provoked the question. You
had not.

Richard.
Jul 20 '05 #12

P: n/a
On Sat, 28 Feb 2004 22:56:04 -0000, Richard Cornford
<Ri*****@litotes.demon.co.uk> wrote:
Mick White wrote:
Michael Winter wrote:
Mick White wrote:
Michael Winter wrote:
> Mick White wrote:
>> <input type="button" name="comment"
>> onclick="comment_text.value=prompt('enter comment')"> ^^^^^^^^^^^^>
> And if I'm not using IE or Opera?


It will also work with Mozilla/Gecko because of the custom scope chain
added to event handling functions generated from attribute code. There
are still a number of other browsers on which it is guaranteed to fail
because they provide no similar mechanism.


Opera is one of the browsers in which it will fail, despite my earlier
assertion to the contrary.

Whilst Opera supports the 'short' shortcut syntax, the event code above
will fail due to (I assume) the changes in scope due to the presence of
the containing form. If that form is removed, or if the reference were
changed to formName.comment_text.value, the handler would execute properly.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #13

P: n/a
Michael Winter wrote: <op**************@news-text.blueyonder.co.uk>
Richard Cornford wrote:
> Michael Winter wrote:
>> Mick White wrote:
>>> onclick="comment_text.value=prompt('enter comment')">

^^^^^^^^^^^^
>>
>> And if I'm not using IE or Opera?


It will also work with Mozilla/Gecko because of the custom scope
chain added to event handling functions generated from attribute
code. There are still a number of other browsers on which it is
guaranteed to fail because they provide no similar mechanism.


Opera is one of the browsers in which it will fail, despite my
earlier assertion to the contrary.

<snip>

I think you will find that it varies slightly with the version, at least
with Opera 7. Opera <= 6 does not provide any special scope handling
mechanism at all so it only stands a chance of resolving the unqualified
identifier when it is spoofing IE.

One of the main problems with using unqualified identifiers as
references to form controls and forms is that it does work on quite a
lot of browsers (and especially the more modern ones). Either because of
special scope chains created for event handling attribute code or
because the reference is available as a named property of the global
object. But I am yet to see two browsers use the same scope handling
mechanism for attribute code.

A convenient "shortcut" feature that isn't always available and
inconsistently implemented when available is best disregarded for
cross-browser scripting. Better to write attribute code as if it was the
code in a function assigned as an event handler with javascript, without
any sort of special scope chain (and without using element names/IDs as
if they were global properties, even without assuming that the - this -
object is in the scope chain, qualifying identifiers for its properties
also with - this). It is almost certainly only inadequate testing (in an
insufficient range of JS capable browsers) that gives people the
impression that this "shortcut" is viable at all.

Richard.

Jul 20 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.