Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Javascript pop up box

  • 09-04-2007 08:51PM
    #1
    Registered Users, Registered Users 2 Posts: 2,592 ✭✭✭


    Hi All

    I am not even sure if this is possible, but here goes anyway. Is it possible to have something like a prompt box which has 2 fields appear when you first access a site [if the data is not already stored in a cookie]. the 2 fields are

    1. input box for a name
    2. Selection box for the user to select which country.

    When these are entered I store them in a cookie, I have the prompt for the users name working and storing the data but I have no idea how to put a drop down box in the prompt. Anybody got any ideas on how this can be done if possible.

    Regards
    Tommy


Comments

  • Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭smcelhinney


    Depends, is the popup a modal dialog, or an actual popup HTML window? A modal dialog is a browser dialog which, in javascript, is generated using either alert(); or prompt();

    AFAIK, modal dialogs dont support dropdown boxes, so I would suggest you do this in a HTML popup, using a select box.
    <select name="country">
       <option value="Ireland">Ireland</option>
       ....
    </select>
    

    Im sure you can do this also in VBScript as an ActiveX, but I wouldnt recommend it, as it causes issues with different browsers.

    HTH,
    Stephen


  • Registered Users, Registered Users 2 Posts: 2,592 ✭✭✭tommycahir


    hi smcelhinney

    Thx for the quick reply. It is a Browser dialog called by the prompt command. So I take it from the below that I need to create a new html page and use the select tag to put in the dropdown box.

    Do you have any example code of how to create a html popup box or how to retrieve the values from it?


  • Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭smcelhinney


    Yeah quite simple.

    Create your HTML page with a form
    <form action="blah.php">
       <label for="name">Name: <input type="text" id="name" name="name" /></label>
       <label for="country">Country <select name="country" id="country">
    <option value="Ireland">Ireland</option>
    ... (you can populate these : ) )
    </select></label>
    <input type="submit" name="submit" id="submit" value="Submit" />
    </form>
    

    Say you call this page setcookie.html
    Then, in the first page of your site, before the <body> tag
    function popupCookie(){
        var newwin = window.open('setcookie.html', 'cookieWin', 'scrollbars=no, width=500, height=500'); // Set these to whatever size you want the window
        newwin.focus(); //sets the focus to the newly created window. 
    } 
    window.onload  = popupCookie();
    

    That should do it. Note though, this wont appear for browsers that have javascript turned off, you should have a non-script version further down the page, like
    <noscript>You dont appear to have javascript enabled, but this site uses cookies. <a href="setcookie.html">Click here to set the cookie</a>. </script>
    

    Hope this helps ya, any other q's gimme a shout : )

    Stephen


  • Moderators, Politics Moderators, Paid Member Posts: 44,344 Mod ✭✭✭✭Seth Brundle


    Presumably most new browsers will kill the pop up before it gets to open.

    Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/ .



  • Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭smcelhinney


    Yep, but Im sure the OP is already aware of that, which is why I didnt address it.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,279 ✭✭✭✭Eoin


    kbannon wrote:
    Presumably most new browsers will kill the pop up before it gets to open.

    I have noticed that popups that are loaded without any user interaction (e.g. on page load) are normally blocked, but ones that are loaded when an object is clicked have a better chance of being displayed.


  • Registered Users, Registered Users 2 Posts: 21,279 ✭✭✭✭Eoin


    kbannon wrote:
    Presumably most new browsers will kill the pop up before it gets to open.

    I have noticed that popups that are loaded without any user interaction (e.g. on page load) are normally blocked, but ones that are loaded when an object is clicked have a better chance of being displayed.


Advertisement