Results 1 to 2 of 2

Thread: Making Combox Viewer Script Dynamic

  1. #1
    Join Date
    Jan 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Making Combox Viewer Script Dynamic

    1) Script Title: Combo-Box Viewer

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...omboviewer.htm

    3) Describe problem: I'm using this script to create a select menu that is populated from a MySQL database with corresponding data to be displayed inside the div.

    I can get the select menu populated easy enough. The problem comes in getting the option value to use it to create a recordset for the additional data. The original DD script does not specify a value for the <option> so I'm wondering if something else needs to be added to the script to store the option value.

    Here's what I have so far:

    Code:
    <form name="dropmsgform">
    <select name="dropmsgoption" size="1" onChange="expandone()">
    <option selected>-- Choose A League --</option>
    
    <?php while ($row_Recordset1 = mysql_fetch_array($Recordset1))
    {
    ?>
    <option value="<?php echo $row_Recordset1['name']; ?>"><?php echo $row_Recordset1['name']; ?></option>
    <?php } ?>
    </select>
    </form>
    
    
    <?php 
    for ($i=1; $i <= $totalRows_Recordset1; $i++) {
    echo "<div id='dropmsg" . $i . "' class='dropcontent'>";
    echo $row_Recordset1['name'];
    echo "</div>"; 
    }
    ?>
    The select menu works; the incrementation of the dropmsg #'s work. The only thing that doesn't work is the display of the league name inside the div. I think it must because there is nothing in the original script to handle the value of the option from the select menu.

    Am I right? Is what I'm trying to do even possible?
    Last edited by So_Cute; 08-06-2007 at 09:58 PM.

  2. #2
    Join Date
    Jan 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Well, I'm a firm believer that one must try to help oneself before expecting anyone else to help, so I've tried to get a little further on my own before posting a follow-up.

    I've pretty much figured out that I need to add to the script to pull the value of the options in the drop down menu. I've been able to get the value, but I really don't know what to do with it from there. Once I get the value,I need to compare it with an id# in a resultset and then display the info for that row inside the div, but I'm not sure how to make the connection.

    Any help at all is appreciated.

    Here's what I have so far:

    Code:
    <script type="text/javascript">
    
    /*
    Combo-Box Viewer script- Created by and &#169; Dynamicdrive.com
    Visit http://www.dynamicdrive.com/ for this script and more
    This notice MUST stay intact for legal use
    */
    
    if (document.getElementById){
    document.write('<style type="text/css">\n')
    document.write('.dropcontent{display:none;}\n')
    document.write('</style>\n')
    }
    
    function contractall(){
    if (document.getElementById){
    var inc=0
    while (document.getElementById("dropmsg"+inc)){
    document.getElementById("dropmsg"+inc).style.display="none"
    inc++
    }
    }
    }
    
    function expandone(){
    if (document.getElementById){
    var selectedItem=document.dropmsgform.dropmsgoption.selectedIndex
    var user_input=document.dropmsgform.dropmsgoption.options[document.dropmsgform.dropmsgoption.selectedIndex].value //add on: get value from options - this works
    contractall()
    document.getElementById("dropmsg"+selectedItem).style.display="block"
    //alert(user_input)
    }
    }
    
    if (window.addEventListener)
    window.addEventListener("load", expandone, false)
    else if (window.attachEvent)
    window.attachEvent("onload", expandone)
    
    </script>
    
    <form name="dropmsgform">
    <select name="dropmsgoption" size="1" onChange="expandone()">
    <option selected>-- Choose A League --</option>
    
    <?php 
    mysql_data_seek($Recordset1, 0);
    while ($row_Recordset1 = mysql_fetch_array($Recordset1))
    {
    ?>
    <option value="<?php echo $row_Recordset1['num']; ?>"><?php echo $row_Recordset1['name']; ?></option>
    <?php } ?>
    </select>
    </form>
    
    <div id="dropmsg0" class="dropcontent">
    
    		<table align="center" border="0" cellpadding="0" cellspacing="0" width="100&#37;">
    		<?php do { ?>
    		<tr>
    		<td>display data here</td>
    		</tr>
    		<?php } while ($row_Recordset2 = mysql_fetch_assoc($Recordset2)); ?>
    		</table>
    </div>
    
    
    <?php 
    for ($i=1; $i <= $totalRows_Recordset1; $i++) {
    echo "<div id='dropmsg" . $i . "' class='dropcontent'>";
    
    //$tnum=(This needs to be theoptionvalue from the dropdown);
    
    mysql_select_db($database_connection, $connection);
    $query_Recordset3 = "SELECT * FROM standings WHERE num = '$tnum'";
    $Recordset3 = mysql_query($query_Recordset3, $connection) or die(mysql_error());
    $row_Recordset3 = mysql_fetch_assoc($Recordset3);
    $totalRows_Recordset3 = mysql_num_rows($Recordset3);
    
    		//do {
    		display data here
    		//} 		
    		//while ($row_Recordset3 = mysql_fetch_assoc($Recordset3));
    //echo "Coming Soon";
    echo "</div>"; 
    
    }
    ?>

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
  •