Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2009
    Location
    Bristol, England
    Posts
    43
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Cool dropdown box issue

    Below, is a code I've been working on where the user searches and selects an item in the drop-down list, and it'll automatically open that page in a new window. It doesn't seem to work at all!
    Can anybody correct this?

    Here's the code:

    Code:
    <html>
    
    <head>
    <meta http-equiv="Content-Language" content="en-gb">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Direct access</title>
    
    </head>
    
    <body OnLoad=" document.form.functioninput.focus()" link="#000000" vlink="#000000" alink="#808080" style="font-family: Arial; color: #000000; font-size: 10pt" bgcolor="#CCCCCC" topmargin="5" leftmargin="5" rightmargin="5" bottommargin="5">
    
    <!-- Security -->
    <body oncontextmenu="return false;">
    
    
    <table border="0" width="100%" cellpadding="11">
    	<tr>
    		<td valign="top">
    		<script type="text/javascript">
    
    // this is the javascript array holding the function list
    // array of arrays
    var functionList = [
        [ "name1", "http://url1" ],
        [ "name2", "http://url2" ],
    ];
    
    // This is the function that refreshes the list after a keypress.
    // The maximum number to show can be limited to improve performance with
    // huge lists (1000s of entries).
    // The function clears the list, and then does a linear search through the
    // globally defined array and adds the matches back to the list.
    function handleKeyUp(maxNumToShow)
    {
    	selectObj = document.forms[0].functionselect;
    	textObj = document.forms[0].functioninput;
    
    	if(document.forms[0].functionradio[1].checked == true)
    	{
    		strText = "^"+textObj.value;
    	}
    	else
    	{
    		strText = textObj.value;
    	}
    	var numShown;
    
    	re = new RegExp(strText,"gi");
    
    	ClearOptionsFast('functionselect');
    	selectObj = document.forms[0].functionselect;
    
        numShown = 0;
        for(i = 0; i < functionList.length; i++)
        {
            var listEntry = functionList[i];
            
            // for first version above, array of arrays:
            if ( listEntry[0].search(re) != -1)
            {
                selectObj[numShown++] = new Option( listEntry[0], listEntry[1] );
            }
    
            // for second version above, array of objects:
            if ( listEntry.name.search(re) != -1)
            {
                selectObj[numShown++] = new Option(listEntry.name, listEntry.url );
            }
    		if(numShown == maxNumToShow)
    		{
    			break;
    		}
    	}
    	if(selectObj.length == 1)
    	{
    		selectObj.options[0].selected = true;
    	}
    }
    
    function ClearOptionsFast(id)
    {
    	var selectObj = document.getElementById(id);
    	var selectParentNode = selectObj.parentNode;
    	var newSelectObj = selectObj.cloneNode(false); // Make a shallow copy
    	selectParentNode.replaceChild(newSelectObj, selectObj);
    	return newSelectObj;
    }
    
    
    // this function gets the selected value and loads the appropriate
    // php reference page in the display frame
    // it can be modified to perform whatever action is needed, or nothing
    function handleSelectClick()
    {
    	selectObj = document.forms[0].functionselect;
    	textObj = document.forms[0].functioninput;
    	if(selectObj.selectedIndex == -1) {
    		return;
    	}
    
    	selectedValue = selectObj.options[selectObj.selectedIndex].text;
    
    	selectedValue = selectedValue.replace(/_/g, '-') ;
    	parent.frames["functiondisplay"].location.href= "http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q="+selectedValue+"";
    	//http://www.php.net/manual/en/function."+selectedValue+".php";
    
    }
    
    function initpage() {
    	handleKeyUp(18);
    	document.forms[0].functioninput.focus();
    }
    </script>
    		<table>
    			<tr>
    				<td valign="top" align="left">
    				<form name="form" onSubmit="handleSelectClick();return false;" action="#">
    					<p>
    <input onKeyUp="handleKeyUp(1000);" type="text" name="functioninput" autocomplete=off placeholder="Search for anything" VALUE="" style="font-size:10pt;width:34ex; font-family:Arial; color:#000000; font-weight:bold" size="40"><br>
    <select onClick="handleSelectClick();" name="functionselect" id="functionselect" size="20" style="font-size:10pt;width:590;height:384"></select></p>
    					<table border="0" width="100%">
    						<tr>
    							<td align="center" width="150">
    <div align="left">
    &nbsp;<p>&nbsp;</p>
    <table border="0">
    	<tr>
    		<td align="center" width="125">
    		<p align="left"><label for="contains"><font size="3"><input type="radio" name="functionradio" checked id="contains" onchange="handleKeyUp(20);"></font><font size="2">Containing</font></label></td>
    		<td align="center" width="125">
    		<p align="left"><label for="starts"><font size="3"><input type="radio" name="functionradio" id="starts" onchange="handleKeyUp(20);"></font><font size="2">Starting With</font></label></td>
    		<td align="center" width="125">
    <input type="button" onClick="handleKeyUp(5000);" value="List everything" style="font-family: Arial; "></td>
    	</tr>
    </table>
    </div>
    						</tr>
    					</table>
    				</form></td>
    			</tr>
    		</table>
    		</td>
    	</tr>
    </table>
    
    </body>
    
    </html>
    Your friendly neighbourhood, James Parker.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,581
    Thanks
    23
    Thanked 643 Times in 642 Posts
    You should not double post. Posted in javascript http://www.codingforums.com/showthread.php?t=280216


  •  

    Tags for this Thread

    Posting Permissions

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