Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javascript pop up box

Options
  • 09-04-2007 9:51pm
    #1
    Registered Users Posts: 2,593 ✭✭✭


    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 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 Posts: 2,593 ✭✭✭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 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 Posts: 38,953 Mod ✭✭✭✭Seth Brundle


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


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


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


  • Advertisement
  • Moderators, Category Moderators, Motoring & Transport Moderators Posts: 21,238 CMod ✭✭✭✭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.


  • Moderators, Category Moderators, Motoring & Transport Moderators Posts: 21,238 CMod ✭✭✭✭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