SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2003
    Location
    Melbourne, Australia
    Posts
    463
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    display html depending on selected items in listbox

    hi all

    i'm after some script to display some html depending on what
    is selected in a list box
    the html i want to display are checkboxes so it's more stuff for a form
    i'm using lotus notes, so i have to use javascript

    i can get it to display a checkbox if a particular item is selected
    but it won't show up in place, it loads a new page
    with the check box the only thing on that new page

    the code i'm using is very basic

    Code:
    function updateChecks()
    {
    string = "";
    if (document._WEBRequest.dataReq.value == "blah") {
    string = "<input type=\"checkbox\" name=\"check\" />";
    string += "Boundary";
    }
    return string;
    }
    function writeChecks()
    {
    document.write(updateChecks());
    }
    the writeChecks() function is called onChange for the listbox

    also don't have much clue as to how to make it show
    more checkboxes if more than one item is selected in the listbox

    thanks for any help

  2. #2
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    document.write(...) will always write to a new page once the original page has finished loading. What you want to do (if you want the checkboxes to appear on the same page) is use a div for the boxes to appear in and dHTML (document.layers, document.all, document.getElementById) to write to the div. (If interested, see the "dHTML: an Introduction" script/tutorial at my site -- GrassBlade)

    Insofar as the multiple selections:
    Code:
    function a(selObj)
    {
     for (var i =0;i < selObj.length;i++)
    	 if (selObj.options[i].selected)
    		 alert(selObj.options[i].value);
    }
     
    <select multiple onchange='a(this)'>
    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


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
  •