Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Retrieve Information From An Alert Box

Status
Not open for further replies.

scripter73

Programmer
Apr 18, 2001
421
US
Hi,

I have a Javascript function that's called when the user selects a choice from a drop-down box in my HTML code.

Presently, the alert box pops up the choice that the user entered. My question - How can I retrieve the Name/Phone number from a user using an Alert box? Also, I'd like to put the values in a variable somewhere.

I'm sure I've done it before, its just been a while.

Here's what I have so far:


function process_report(){
if (document.form1.reportby.value != "Charter Policyholder")
window.alert('You selected ' + document.form1.reportby.value);
*(instead I want to ask the user their name/number and return it to some variable)*
}
 
var Answer = prompt("Some Text", "Default text");

then Answer contains whatever they type.
 
Sorry, hit submit by accident. Add to that: Some Text is the message the user sees in the alert and Default Text is the message that's displayed (but can be overwritten by user) in the text bar.
 
Thanks, that worked like a charm! One more question. Is there anyway to accept more than one parameter from the user in the same prompt box?

Thanks,
scripter73
 
Ummm....I don't think so. What you could do (and this is just off the top of my head) is to get the user to seperate items with...say...a comma. Then use the split method in javascript to split the string into an array of strings.

It's not perfect but it's all I can think of at the moment.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top