JavaScript - Javascript Dual Select
Hi,
would someone know how to convert the left side (textbox) into the same thing as the right has (select box) also by modifying the JS code from the example of this URL: http://www.mredkj.com/tutorials/tableaddrow.html ? It would be a really good feature to have if two select options were used from side-to-side rather than a textbox and a select list. Similar TutorialsOk so I'm making this form which when a selection is made in one box it will run through the javascript(function getMgmtHours), and update the div(mgmthours). Then another box shows up allowing another selection to be made which runs through the javascript(function getDays) and updates another div(mgmtdate). My problem is that when I use the second box to run through javascript, it overwrites what shows up in the first div (mgmthours) when it should be updating a different div (mgmtdate). Any ideas what I can do to get it update the relevant div and not overwrite the other one? Here is part of the javascript I have in my page head: Code: function getMgmtHours(str) { if (str=="") { document.getElementById("mgmthours").innerHTML=""; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("mgmthours").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getmgmthours.php?dist="+str,true); xmlhttp.send(); } function getDays(str) { if (str=="") { document.getElementById("mgmtdate").innerHTML=""; return; } if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("mgmtdate").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getdates.php?sunday="+str,true); xmlhttp.send(); } Here is the HTML/PHP portion being used: PHP Code: echo "<p>"; echo "Submit hours:"; echo "<form>"; echo "<select name='district' onchange='getMgmtHours(this.value)'>"; echo "<option value=''>Select a district:</option> <option value='1'>1</option> <option value='3'>3</option> <option value='4'>4</option>"; echo "</select>"; echo "</form>"; echo "</p>" echo "<p>"; echo "<form action='./hours.php' method='post' onSubmit='return checkMgmtHours'>"; echo "Weekending Day: "; echo "<select name='weekending' onchange='getDays(this.value)'>"; echo "<option value=''>Choose a Date:</option>"; while ($week < 32) { $nextsunday = strtotime("next Sunday"); if ($week > 0) { $timestamp = strtotime("-" . $week . " week", $nextsunday); } else { $timestamp = $nextsunday;} $weekending = date('M. d, Y', $timestamp); echo "<option value='" . $weekending . "'>" . $weekending . "</option>"; $week = $week + 1; } echo "</select>"; echo "<div id='mgmtdate' />"; echo "<div id='mgmthours' />"; echo "</p>"; Edit: Also, after getMgmtHours() runs, I can still use both getDays and getMgmtHours, howeer once I used getDays, I am no longer able to use getMgmtHours w/o refreshing the page. Ok I need to open a popup in a second monitor. The browser will be open in the first monitor and the popup needs to open in the second monitor (we'll say it's to the left for now). I have tried a few Javascript methods. I don't have PHP avaliable to me in this case but I do have the ability to use JSP and will shortly have JQuery. Here is what I have tried so far: Code: <script type="text/javascript"> function popup(url, winName, xOffset, yOffset) { var x = (window.screenX || window.screenLeft || 0) + (xOffset || 0); var y = (window.screenY || window.screenTop || 0) + (yOffset || 0); return window.open(url, winName, 'top=' +y+ ',left=' +x); } </script> <form> <input type="button" onClick="popup('http://www.google.com', 'myWin', -600, 100)" value="Show Customer"/> </form> and Code: <script type="text/javascript"> function popup() { window.open( "http://igatedev.kirbyrisk.com/DualMonitorTest/product.jsp?part=545347", "myWindow", "status=0, fullscreen=0, resizable=1" ) } </script> Any help is much appreciated. Also I was wondering if there was a way to have the popup close with the original window, or with a button click from the first. Hi Guys, I have a Javascript function that toggles a 'show/hide' table row: //CONTROL Code: <a href="#" onclick="toggle('ROW 1, this)"><img src="../../Images/plus.gif" border="0" /></a> //JAVASCRIPT Code: function toggle(id, obj) { var matchingElements = new Array(); if (document.getElementsByClassName) { matchingElements = document.getElementsByClassName(id); } else { var elements = document.getElementsByTagName("tr"); for (i = 0; i < elements.length; i++) { if (elements[i].className == id) { matchingElements[matchingElements.length] = elements[i]; } } } for (i = 0; i < matchingElements.length; i++) { toggleDisplay(matchingElements[i], obj); } } function toggleDisplay(element, obj) { if (element.style.display == "none") { element.style.display = "block"; obj.innerHTML = "<img src=\"../../Images/minus.gif\" border=\"0\">"; } else { element.style.display = "none"; obj.innerHTML = "<img src=\"../../Images/plus.gif\" border=\"0\">"; } } Which works fine, but what I need is something like this: Control 1: Toggle - ROW 1 (+ Close ROW 2 (if visible)) Control 2: Toggle - ROW 2 Is this a Javascript or PHP issue? Hi, I'm after a drop down script that basically you press categories and down it drops with say one side products by category the left side and say product by price the right side. Ign.com do it when you click on one of the top links I'm just not sure of the name and the most easiest to implement? Any help wolf be great Many thanks Joe Hello all, my second post! I finally got the below script working in Firefox and was really pumped about it until I realized it didn't load in Google chrome or Safari. What this script does is its a dual onclick event which makes a hidden div appear and loads an iframe within the now visible div. Here is the code, I would love any input on how to make this work in other browsers. Here is the header code: Code: <SCRIPT type="text/javascript"> <!-- var state = 'none'; function showhide(layer_ref) { if (state == 'block') { state = 'none'; } else { state = 'block'; } if (document.all) { //IS IE 4 or 5 (or 6 beta) eval( "document.all." + layer_ref + ".style.display = state"); } if (document.layers) { //IS NETSCAPE 4 or below document.layers[layer_ref].display = state; } if (document.getElementById &&!document.all) { hza = document.getElementById(layer_ref); hza.style.display = state; } } //--> </script> <SCRIPT type="text/javascript"> function loadIframe(iframeName, url) { if ( window.frames[iframeName] ) { window.frames[iframeName].location = url; return false; } else return true; } </script> Here is the code on the page where a link click shows the hidden div and loads the iframe contained. Code: <p><a href="#" onclick="showhide('div1');return loadIframe('ifrm1', 'http://www.google.com');">show/hide me</a></p> </td></tr> <div id="div1" style="display: none; position: fixed; z-index:4; width: 1010px; height: 500px; left: 5%; top: 15%; background-color: #f0f0f0; border: 1px solid #000; padding: 10px;"><iframe name="ifrm1" id="ifrm1" width="100%" height="90%" scrolling="yes" frameborder="0">Sorry, your browser doesnt support iframes.</iframe><p><a href="#" onclick="showhide('div1')">close</a></div>'; As always, any input is greatly appreciated! I have got this piece of code where JavaScript will change a FORM OPTION if it has been selected before (incase the user returns to the page - doesn't have to refill in things), but its not working and my web browser reports this error: Quote: Error: document.getElementById("Dr") is null This is the code: Code: <SCRIPT type="text/javascript"> document.getElementById("<?php echo $_SESSION['recipient']['title']; ?>").selected = "selected"; </SCRIPT> Code: <FORM action="process.html" method="post"> <DIV class="deliveryinformationdata"> <DIV> <B>Title:</B> <SELECT name="title"> <OPTION></OPTION> <OPTION id="Dr">Dr</OPTION> <OPTION id="Miss">Miss</OPTION> <OPTION id="Mr">Mr</OPTION> <OPTION id="Mrs">Mrs</OPTION> <OPTION id="Ms">Ms</OPTION> </SELECT> </DIV> <INPUT type="submit" value="Submit"> </DIV> </FORM> Can anyone see a problem? Hi all, I am a newbie to JS. So please extend your help suggesstion to solve this problem I have. I have 2 select boxes. Data in one select box is corresponding to the data in the other select box. When the user comes in and selects example the 3rd element from the first or second select box the correspoinding 3rd element from the other select box should be selected. Please help with the solution.Thanks in advance Hi Guys, I am posting this to see if anyone has any ideas or sample code that has worked in the past. What i am aiming at doing is having two tables, with the same amount of rows side by side, effectively rendering them the same. I wish then to select a row on the one table, and this event would trigger the same row on the 2nd table to be selected too. Has anyone done something like this before? Appreciate any feedback! Thanks. Here's the code that I'm working with: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type ="text/javascript"> function HouseSel(){ document.getElementById("HouseSelect").value = '3' alert (document.getElementById("HouseSelect").value); } </script> </head> <body> <form action="https://www.paypal.com/us/cgi-bin/webscr" method="post" name="_xclick"> <select name="item_name" id="HouseSelect"> <option value="0" selected="selected">--Please Select a House--</option> <option value="1">Nags Head</option> <option value="Rent Deposite: Calib ">Calibre</option> </select> <input name="calculate3" type="button" id="calculate3" tabindex="2" onclick="HouseSel(); " value="Calculate"/> </form> </body> </html> But it's still returning the initial value. How do I get it to 3? Hello guys, I am working with javascript and currently have the below code set up. This works well, however I would like to change the "select box" to a "search box"- When the user enters a search string, the matching DIV appears. If there is no matching DIV then "sorry nothing found" appears. Is this possible at all? Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript"> </head> <body> <script type="text/javascript"> function show(obj) { no = obj.options[obj.selectedIndex].value; count = obj.options.length; for(i=1;i<=count;i++) document.getElementById('fleet'+i).style.display = 'none'; if(no>0) document.getElementById('fleet'+no).style.display = 'block'; } </script> <form name="myForm"> <select onchange="show(this)"> <option value="1">Please Choose</option> <option value="2">120</option> <option value="3">121</option> <option value="4">122</option> </select> </form> <div id="fleet1" style="display:block">Please Choose <br> </div> <div id="fleet2" style="display:none"> <br> <table valign="top" align="center" border="0" width="690" style="border-collapse: collapse" cellpadding="0" cellspacing="0" bgcolor="#336699"> <TR border="0" bordercolor="#FFFFFF"> <TD valign="top"> <?php include("php/fleet/includes/table.php"); ?> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/php/fleet/120.php"; include_once($path); ?></tr></table> </td> </tr> </table></div> <div id="fleet3" style="display:none"> <br> <table valign="top" align="center" border="0" width="690" style="border-collapse: collapse" cellpadding="0" cellspacing="0" bgcolor="#336699"> <TR border="0" bordercolor="#FFFFFF"> <TD valign="top"> <?php include("php/fleet/includes/table.php"); ?> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/php/fleet/121.php"; include_once($path); ?></tr></table> </td> </tr> </table></div> <div id="fleet4" style="display:none"> <br> <table valign="top" align="center" border="0" width="690" style="border-collapse: collapse" cellpadding="0" cellspacing="0" bgcolor="#336699"> <TR border="0" bordercolor="#FFFFFF"> <TD valign="top"> <?php include("php/fleet/includes/table.php"); ?> <?php $path = $_SERVER['DOCUMENT_ROOT']; $path .= "/php/fleet/122.php"; include_once($path); ?></tr></table> </td> </tr> </table></div> </body> </html> demo can be seen he http://www.nctfleetlist.co.uk/div.php Hey, how do I make the following accessible if JS is disabled? Code: <select onchange="if (this.selectedIndex > 0) location.href=this[this.selectedIndex].value;"> <option value="www.domain.com">Your Domain</option> </select> Hi all, I am newbie to JS. I have the below task. Please advise. I have a result set of a query being displayed on a page. (5000+ rows). I have to provide a search capability, a search box which will enable to enter a position ID number and the entered position ID by the user should be selected from the results in a different color. Can you please help me with the above. Thanks in advance Calculating quiz answers? Code: var correctAnswers = new Array(); correctAnswers[1] = "Extensible Hypertext Markup Language"; correctAnswers[2] = "<p></p>"; correctAnswers[3] = "<br />"; function checkAnswers(){ var score = 0; for (i=1; i<4; i++){ correctAnswers = getSelectValue("quiz","q" + i); if (correctAnswers == correctAnswers[i]){ score++; } } I'm trying to do this using numerical arrays for an assignment: Create a webpage with three select boxes. If basketball is selected in the first select box, the second select box should display the names Celtics, Lakers, and Bulls. If Celtics is selected from the second select box, the third select box should display the names Larry Bird, Bill Russell, and Kevin McHale. I think i have a good start but i can't seem to get the fields to automatically populate with the players. This has to be done solely with JavaScript. Any help would be greatly appreciated? <html> <head> <script type="text/javascript"> <!-- var teams = new Array() teams[1] = new Array() teams[1][0] = "Celtics" teams[1][1] = "Lakers" teams[1][2] = "Bulls" teams[2] = new Array() teams[2][0] = "Yankees" teams[2][1] = "Cardinals" teams[2][2] = "Reds" var basketball = new Array() basketball[0] = new Array() basketball[0][0] = "Larry Bird" basketball[0][1] = "Bill Russell" basketball[0][2] = "Kevin McHale" basketball[1] = new Array() basketball[1][0] = "Wilt Chamberlain" basketball[1][1] = "Jerry West" basketball[1][2] = "Magic Johnson" basketball[2] = new Array() basketball[2][0] = "Micheal Jordan" basketball[2][1] = "Scottie Pippen" basketball[2][2] = "Dennis Rodman" var baseball = new Array() baseball[0] = new Array() baseball[0][0] = "Babe Ruth" baseball[0][1] = "Joe DiMaggio" baseball[0][2] = "Mickey Mantle" baseball[1] = new Array() baseball[1][0] = "Mark McGuire" baseball[1][1] = "Ozzie Smith" baseball[1][2] = "Willie McGee" baseball[2] = new Array() baseball[2][0] = "Pete Rose" baseball[2][1] = "Johnny Bench" baseball[2][2] = "Joe Morgan" function fillTeams() { var whichIndex = document.getElementById("theSport").selectedIndex var numberOfTeams = teams[whichIndex].length for(i=0;i < numberOfTeams; i++){ document.getElementById("theTeams").options[i].text = teams[whichIndex][i] } } function fillPlayers() { var whichIndex = document.getElementById("theTeams").selectedIndex if(document.getElementById("theTeams").selectedIndex=="basketball") var numberOfPlayers = teams[teams[whichIndex]].length for(i=0;i < numberOfPlayers; i++) { document.getElementById("thePlayers").options[i].text = basketball[teams[whichIndex]][i] } else if(document.getElementById("theTeams").selectedIndex =="baseball") for(i=0;i < numberOfPlayers; i++) { document.getElementById("thePlayers").options[i].text = basketball[teams[whichIndex]][i] } } //--> </script> </head> <body> <form> <select id="theSport" onChange="fillTeams()"> <option>Choose a Sport</option> <option>Basketball</option> <option> Baseball </option> </select> <select id="theTeams" onChange="fillPlayers()"> <option>................</option> <option></option> <option></option> </select> <select id="thePlayers" size="3"> <option> ...............</option> <option></option> <option></option> </select> </form> </body> </html> I have the following code but it simply writes the path to the webpage. I actually want it to randomly select the .js code in that path and run it. Help please! Code: jsFiles= new Array(3) jsFiles[0]=["assets/base/scripts/itmpiscripts/popupad1/script.js"] jsFiles[1]=["assets/base/scripts/itmpiscripts/popupad2/script.js"] jsFiles[2]=["assets/base/scripts/itmpiscripts/popupad3/script.js"] randno = Math.floor ( Math.random() * jsFiles.length ); document.write(jsFiles[randno]); Thanks Hi All, I have a select html control as below ; <SELECT > <OPTION VALUE="1"> This is option 1 </OPTION> <OPTION VALUE="2" >This is option 2 </OPTION> <OPTION VALUE="3" >This is option 3 </OPTION> </SELECT> My requirement is that when user moves pointer over the items the value of the item should be shown in a hint box. How could I show the value of the item in a hint box as user moves pointer over an item using javascript? Thanks, Dev Code: I have to create two dropdownlists that are dependent In my first select tag there are 4 selections ,,, year,quarter,month and week. and in second select it should automatically populate..If user select year from first select in second select values should be 1 to 365.. if quarter values in second select(dropdown) should be 1 to 4. if month 1 to 12 and if week is selected 1 to 7.. can anyone help me to achieve this.. I will post that code and please help me to resolve this error as iam naive user to javascript.. <select id="user_defn_uom" name="user_defn_uom" onchange="alert(this.options[this.selectedIndex].text)" align="center"> <option selected value=""> <option value="Yearly">Yearly <option value="Quarterly">Quarterly <option value="Monthly">Monthly <option value="Weekly">Weekly </td> <td>. <select name="user_defn_day" align="center"> <option selected value=""> <script type="text/javascript"> alert(this.options[this.selectedIndex].text) for (var i = 1; i <=366; i++) { document.write('<option value="' + i + '">' + i + '</option>'); } </script> </select> I am trying to make images change as the user selects the option from the dropdown menu , I have called alert("test1"); alert("test2"); to check if the functions are being called but only the first one happens, can you please tell me what's wrong with the script. Here is the script:
Code: var oImageChooser; addEvent( window, "load", initialize) function initialize() { alert("test1"); var oImageChooser = document.getElementById("imageChooser"); addEvent(oImageChooser, "change", loadCached); } var imageLibrary = new Array(); imageLibrary["image1"] = new Image(120,90); imageLibrary["image1"].src = "images/desk1.gif"; imageLibrary["image2"] = new Image(120,90); imageLibrary["image2"].src = "images/desk2.gif"; imageLibrary["image3"] = new Image(120,90); imageLibrary["image3"].src = "images/desk3.gif"; imageLibrary["image4"] = new Image(120,90); imageLibrary["image4"].src = "images/desk4.gif"; function loadCached() { alert("test2"); var imgChoice = oImageChooser.options[oImageChooser.selectedIndex].value; document.getElementById("thumbnail").src = imageLibrary[imgChoice].src; } here is the html Code: <html> <head><title>Image dropdown</title> <script type = "text/javascript" src = "experimento5.js"> </script> </head> <body onload = "initialize()"> <h1> Choose any image</h1> <img id = "thumbnail" src = "images/desk1.gif" > <form> <select id = "imageChooser"> <option value = "image1"> Bands</option> <option value = "image2"> Clips</option> <option value = "image3"> Lamp</option> <option value = "image4"> Erasers</option> </select> </form> </body> </html> Hi codingforums.com, i have been working on a programm for some time and now i have decided to include some javascript to it and have only very limited knowledge so i copied something from a website and tried to modifiy it but only with partial success. Would be awesome if someone can guide me a littlebit. So i have 2 select boxes and want the second one to be filled depending on the chosen option from the first one. And 'on the fly' so with imediate change. So now i have the following code which gives me the first selectbox sucessfully filled with 'customers' in that case but i dont manage to give the second one listed in order, the are all on the same line displayed as one option. here my code: Code: <?php //read html header require('html/header.html'); //error display error_reporting(E_ALL); ini_set('display_errors', 1); include('conn.php'); ?> <div align="center"> <form name="classic"> <select name="customer" size="5" onChange="updatesystem(this.selectedIndex)"> <?php //prepare SQL query $query = "SELECT * FROM VIA_CUSTOMER ORDER BY ACRONYM ASC"; //parsing sql statement $statement = oci_parse($conn, $query); //execute sql statement and display results if(oci_execute($statement)) { while(ocifetchinto($statement, $result, OCI_ASSOC)) { echo "<option align='center' value='".$result['ACRONYM']."'"; if(isset($_GET['VIA_CUSTOMER']) && $_GET['VIA_CUSTOMER'] == $result['ACRONYM']) { echo "selected='selected'"; } echo ">".$result['ACRONYM']."</option>"; } } oci_free_statement($statement); ?> </select> <select name="system" size="5" style="width: 150px" onClick="alert(this.options[this.options.selectedIndex].value)"> </select> </form> </div> <script type="text/javascript"> var customerlist=document.classic.customer var systemlist=document.classic.system var system=new Array() system[0]=["ARRAY0", "<?php //prepare SQL query $query = "SELECT NAME FROM VIA_SYSTEM WHERE IDCUSTOMER = 1 ORDER BY NAME ASC"; //parsing sql statement $statement = oci_parse($conn, $query); //execute sql statement and display results if(oci_execute($statement)) { while(ocifetchinto($statement, $result, OCI_ASSOC)) { echo $result['NAME']; } } oci_free_statement($statement); ?>", "ARRAY0.1", "ARRAY0.2"] system[1]=["ARRAY1", "ARRAY1.1", "ARRAY1.2"] system[2]=["ARRAY2"] system[3]=["ARRAY3"] system[4]=["ARRAY4"] function updatesystem(selectedsystemgroup){ systemlist.options.length=0 if (selectedsystemgroup>=0){ for (i=0; i<system[selectedsystemgroup].length; i++) systemlist.options[systemlist.options.length]=new Option(system[selectedsystemgroup][i].split("|")[0], system[selectedsystemgroup][i].split("|")[1]) } } </script> <? //include html footer require('html/footer.html'); ?> now my problem is within this piece of code: Code: <?php //prepare SQL query $query = "SELECT NAME FROM VIA_SYSTEM WHERE IDCUSTOMER = 1 ORDER BY NAME ASC"; //parsing sql statement $statement = oci_parse($conn, $query); //execute sql statement and display results if(oci_execute($statement)) { while(ocifetchinto($statement, $result, OCI_ASSOC)) { echo $result['NAME']; } } oci_free_statement($statement); ?> how can i get the Code: WHERE IDCUSTOMER = 1 to be chosen from the first select box because $_GET wont work obviously and how can i display the results all as single arrays and not one single line? i know this might be a lot to ask but im still learning and cant get past this with just searching google. This is a picture of the output, the first select is good but the second one is the issue and the 'ARRAY0.1' is just dummy data (not from database) so it should be displayed as single lines like so: LSM SQL*LIMS TEST i would be eternally grateful for whom can help me out with this. Regards, The Noob I use this code in a form that posts to two different destinations, I use JavaScript to achieve it. Code: <SCRIPT type="text/javascript"> function submitTo(where) { document.form.action = where; document.form.submit(); } </SCRIPT> <FORM action="" method="post" name="form"> <DIV> <INPUT onClick="return submitTo('1.html')" type="button" value="1"> <INPUT onClick="return submitTo('2.html')" type="button" value="2"> </DIV> </FORM> I am still wanting to do is the same thing, but with drop down menu's (SELECT) instead of INPUT. Is there anyone clever that can think of a solution? I'm still trying to work on it, but haven't thought of anything up yet.. |