SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    auto refresh a list box

    I have a form with a list box. Beside the list box I have a link that opens a new window in order for users to enter new records which then appear in the list box. How do I make the list box refresh to show newly added records? Can I refresh it when it receives the focus or are there better ways to do it? Also, how do I make the new window open to a certain size or to make it maximized?

  2. #2
    SitePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not really sure what you mean by "list box". Do you mean a group of checkboxes? Maybe a select set to display multiple options? Perhaps an unordered list of checkboxes? Could you clarify?

    I suspect what you want to do will best be accomplished with innerHTML, but not if you are changing text values in a textarea, which is more easily done with just changing the textarea's value.

    When opening a window with window.open(), some of the available parameters in the option list are height and width. For example:
    var newWin=window.open("yourfile.html","windowName","height=100,width=200,scrollbars=no");

  3. #3
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably the most logical way:

    1) Give the select - in the 'main' window - an id (e.g., 'foo')
    2) Stick this in the same document:
    Code:
    <script type="text/javascript">
    
    function addOption(sSel_id, sOpt_text, sOpt_val, bIsSelected)
    {
        var oSelect = document.getElementById(sSel_id);
        if (oSelect)
        {
            var newopt = new Option(sOpt_text, sOpt_val);
            oSelect.options[oSelect.options.length] = newopt;
            if (bIsSelected)
                 oSelect.selectedIndex = oSelect.options.length - 1;
        }
    }
    
    </script>
    3) In the return document (the file sent back to the pop-up by your PHP/ASP/JSP after the dB update), put:
    Code:
    <script type="text/javascript">
    
    if (opener && opener.addOption)
        opener.addOption('foo', '[option text here]', '[option value here]', true;
        self.close();
    
    </script>
    The red bits should be the 'filled in' new (displayed) text string and option value. Presumably you'll want your server-side code to confirm their entry. The argument 'bIsSelected' chooses the new option for display, if desired.

    Millions of window-opening scripts around (some on this site, searchable).
    ::: certified wild guess :::


Bookmarks

Posting Permissions

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