Closed Bug 12021 Opened 25 years ago Closed 24 years ago

Javascript prompt is returning bogus value

Categories

(Core :: XUL, defect, P3)

x86
Windows NT
defect

Tracking

()

VERIFIED FIXED

People

(Reporter: slogan, Assigned: danm.moz)

References

Details

(Whiteboard: [nsbeta2+])

The expected behavior (according to my Javascript book) -- on cancel, it should return null. Otherwise, the string entered should be returned. However I can't get this loop to work (it deals with all of the cases): var value; var done = false; while ( done == false ) { value = prompt( "Enter a value", "" ); dump( "value is " + value + "\n" ); // always prints nothing if ( value== null ) done = true; // cancel should take me here, it doesn't else if ( group == "" ) alert( "Please enter a value name" ); // I always get here, even if data was entered else done = true; } As the comments indicate, regardless of what I enter or if I press ok or cancel, I get "" as a rturn value.
In the previous bug report, "group" should be "value". Here is the modified code: var value; var done = false; while ( done == false ) { value = prompt( "Enter a value", "" ); dump( "value is " + value + "\n" ); if ( value == null ) done = true; else if ( value == "" ) alert( "Please enter a value" ); else done = true; }
Assignee: edburns → trudelle
Component: Java APIs to WebShell → XUL
Assignee: trudelle → danm
reassigning to danm. syd, why is this marked critical severity? Critical is supposed to indicate crash, data loss or severe leak.
Assignee: danm → davidm
Looks to me like nsCommonDialogs aren't set up to catch the Cancel button and munge the response appropriately. David?
Assignee: davidm → danm
Nope. The problem is in the DOM where it takes the cancel return value and converts it into a empty nsString rather than returning the expected null pointer. Of course you can't return a null pointer since the string is being passed by reference ;) reassigning back to danm
Severity: critical → major
Status: NEW → ASSIGNED
Target Milestone: M12
mass-moving all m12 bugs to m13
Target Milestone: M13 → M14
*** Bug 23107 has been marked as a duplicate of this bug. ***
BULK MOVE: Changing component from XUL to XP Toolkit/Widgets: XUL. XUL component will be deleted.
Component: XUL → XP Toolkit/Widgets: XUL
Target Milestone: M14 → M15
Target Milestone: M15 → M16
Target Milestone: M16 → M17
Mass-moving all M16 non-feature bugs to M17, which we still consider to be part of beta2
nominating nsbeta2 -- this is base DOM 0 functionality
Keywords: nsbeta2
[nsbeta2+]
Whiteboard: [nsbeta2+]
Blocks: 40158
window.prompt() now returns a null JS value when the user punches "cancel".
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
*** Bug 43660 has been marked as a duplicate of this bug. ***
Updating QA Contact for a verification.
QA Contact: leila.garin → jrgm
verified fixed -- 2000071810 mac/linux, 2000071910 win2k -- window.prompt() returns null on cancel, and the string on OK (incl. "").
Status: RESOLVED → VERIFIED
Component: XP Toolkit/Widgets: XUL → XUL
QA Contact: jrgmorrison → xptoolkit.widgets
You need to log in before you can comment on or make changes to this bug.