473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

returning value from prompt() ??

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


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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Mountain Man | last post by:
Hi, I'm having trouble with the foreach function. I'm using it twice inside a user defined function with two different arrays, and in the second instance it's returning the value of the first...
9
by: mjm | last post by:
Folks, Stroustrup indicates that returning by value can be faster than returning by reference but gives no details as to the size of the returned object up to which this holds. My question is...
11
by: kelvSYC | last post by:
What is the best way to create functions that, based on some input, return either structures or a null value if the structure cannot be made? The problem is that the structure has be created...
3
by: - | last post by:
I have a country table with code and name columns and create a stored procedure 'get_countries()' but have no idea what is the syntax to return multiple rows. I have searched the newsgroups and...
2
by: ambersaria420 | last post by:
I need to prompt the user to enter ID. I can open up prompt fine using javascript code below. However I am not sure how to get value that user entered in user prompt window. I have to check this...
5
by: Robert Fitzpatrick | last post by:
Can someone point me to some more information or perhaps show an example of returning a recordset from a plpgsql function. I'd like to send an argument or arguments to the function, do some queries...
21
by: planetthoughtful | last post by:
Hi All, As always, my posts come with a 'Warning: Newbie lies ahead!' disclaimer... I'm wondering if it's possible, using raw_input(), to provide a 'default' value with the prompt? I would...
7
by: dana_livni2000 | last post by:
how do i print the acuale byte sequence that represent a vairable (let say a char - i want to see the 8 bits). thanks dana
12
by: pyramid | last post by:
I am new to C++, and one of the homework we have pertains to Functions. The problem is: Write a function called isValid that determines whether any 3 values can represent the sides of a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.