like a "prompt" function but better...

Results 1 to 3 of 3

Thread: like a "prompt" function but better...

  1. #1
    Join Date
    Dec 1969

    Default like a "prompt" function but better...

    Hi guys.<BR>I am having trouble with something I&#039;m sure should be fairly easy, but all the tutes I&#039;ve found have confused me!<BR>I want a function to pop-up a window which will display a form with a single select box and submit button. When the submit button is pressed, the pop-up must close and the function that opened it should be notified of the value selected by the user from the select box. In other words, the effect I want is exactly like using a<BR>var userName = prompt("what is your name?")<BR>except that the user chooses from a select instead os a text box. I know I can create a window with<BR>var newWin =, winName, features)<BR>but I don&#039;t know how to get the value of the pop-up&#039;s select element and close the pop-up at the same time.<BR>Thanks in advance

  2. #2
    Join Date
    Dec 1969

    Default You can use opener.

    When you open a popup, the popup has access to an object called "opener". This "opener" object allows you to communicate with the window that opened the popup.<BR><BR>To do what you need, have a function in your main window (the one that opens the popup):<BR>function handlePopupSubmit(arg, arg, arg)<BR>{<BR> // do whatever you want<BR>}<BR><BR>Then, in your popup, you can call that function:<BR>&#060;input type="button" value="Submit" onClick="doSubmit(this.form.textfield.value, this.form.textfield2.value, this.form.textfield3.value);"&#062;<BR><BR>functio n doSubmit(arg, arg, arg)<BR>{<BR> opener.handlePopupSubmit(arg, arg, arg);<BR><BR> this.close();<BR>}

  3. #3
    Join Date
    Dec 1969

    Default Why do you need a submit button?

    If you use onChange on the &#060;SELECT&#062;, you don&#039;t need anything else.<BR><BR>&#060;FORM&#062;<BR>&#060;SELECT onChange="go(this);"&#062;<BR>&#060;OPTION&#062;--choose one--<BR>&#060;OPTION&#062; Apples<BR>&#060;OPTION&#062; Bananas<BR>&#060;OPTION&#062; Cantaloupe<BR>&#060;/SELECT&#062;<BR>&#060;/FORM&#062;<BR>&#060;SCRIPT&#062;<BR>function do(sel)<BR>{<BR> opener.document.userName = this.options[this.selectedIndex].text;<BR> window.close();<BR>}<BR>&#060;/SCRIPT&#062;<BR><BR>So then you simply need a <BR> var userName;<BR>in the main page. <BR><BR>I used the .text property of the selected option so that I didn&#039;t even have to have both VALUE= and text, but if you have a VALUE= that doesn&#039;t match the text, then use .value instead of .text, presumably.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts