JavaScript - Please Help To Select Numbers From A List Box And Add It To A Text Box
hi please help,
i want to select numbers from a list box and add it to a text box with comma separated. my java script code does not work into browser but work fine into eclipse jsp view. Code: function passingNumbersToTextArea(numToCall,allNum) { var numFromList=document.getElementById(allNum); var numToTextArea=document.getElementById(numToCall); if(numToTextArea.value.search(numFromList.value)!=-1)//if duplicate Number is exist { alert("Duplicate Number Can not be added :"); return false; } else { if(numToTextArea.value.length!=0) { // If textarea has value than it added another value with comma seperated numToTextArea.value=numToTextArea.value+','+numFromList.value; return false; } else { numToTextArea.value=numFromList.value; return false; } } } jsp code <h:inputTextarea cols="10" rows="4" id="numberToCall" required="true" value="#{conferenceCall.numberToCall}" styleClass="form_input_box" /> <h:selectOneListbox styleClass="form_selectmenu" id="allNumbers" size="5" onclick="passingNumbersToTextArea('numberToCall','allNumbers');"> <f:selectItem itemValue="9971701077" itemLabel="Sharad : 9971701077"/> <f:selectItem itemValue="9990102381" itemLabel="Saurabh : 9990102381"/> </h:selectOneListbox> javascript debugger shows error Error ``numToTextArea is null'' [x-] in file ``http://localhost:8888/SparkServicePr...ystem/home.jsf'', line 21, character 0. Exception ``TypeError: numToTextArea is null'' thrown from function passingNumbersToTextArea(allNum=string:"allNumbers", numToCall=string:"numberToCall") in <http://localhost:8888/SparkServiceProvisioningSystem/home.jsf> line 21. [e] message = [string] "numToTextArea is null" Exception ``TypeError: numToTextArea is null'' thrown from function onclick(event=MouseEvent:{0}) in <http://localhost:8888/SparkServiceProvisioningSystem/home.jsf> line 1. [e] message = [string] "numToTextArea is null" Error ``TypeError: numToTextArea is null'' [x-] in file ``http://localhost:8888/SparkServicePr...ystem/home.jsf'', line 21, character 0. Thanks & Regards: Saurabh Similar TutorialsHi there. With the below script I'm trying to validate if the user enters a quantity in the text box they must select a reason for ordering and if the user selects a reason code but forgets to enter a quantity it should alert to enter a quantity. Right now it validates the reason code but not the quantity. Please help. Code: <script> function validateReason(){ var tr, i=1; while(tr=document.getElementById('Child'+(i++))){ var txtV=tr.getElementsByTagName('input')[0].value var selS=tr.getElementsByTagName('select')[0].selectedIndex; if(txtV.length>0&&selS==0){alert('If you enter a quantity you must select a reason!');return false} } return true; } </script> <form method="POST" onsubmit="return validateReason(this) ; " action="Order_Process.php" name="theForm" > <table> <tr id='Child1'> <td><input type = 'text' MAXLENGTH='3' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='INSUFFICIENT' >INSUFFICIENT</option> <option value='MISPLACED' >MISPLACED</option> <option value='NOT ORDERED' >NOT ORDERED</option> <option value='PLANOGRAM CHANGE' >PLANOGRAM CHANGE</option> <option value='SHORT' >SHORT</option> </select></td> </tr> <tr id='Child2'> <td><input type = 'text' MAXLENGTH='3' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='MISPLACED' >MISPLACED</option> <option value='SHORT' >SHORT</option> </select></td> </tr> <tr id='Child3'> <td><input type = 'text' MAXLENGTH='3' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='MISPLACED' >MISPLACED</option> <option value='SHORT' >SHORT</option> </select></td> </tr> </table> <input type="submit" value="submit" name="submit"> </form> I've been tasked to create a form where the user types a numeric item id into a text field. Typing this numeric item id into the field will update a select list when the item id matches a select list value. Can anyone help me with this as I don't know where to start?
Hey Guys When a user changes the select list called "reason_code_master" I need the uodatecodes() function to update all the other select list with the id of "reason_codes" with the same . How can I do this. <select size='1' onchange="updatecodes()" name='reason_code_master'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> <select size='1' name='reason_codes' id='reason_codes'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> <select size='1' name='reason_codes' id='reason_codes'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> <select size='1' name='reason_codes' id='reason_codes'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> <select size='1' name='reason_codes' id='reason_codes'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> Hi all, I have been struggling on a bit of code for a while now. I need to populate a second drop down list (Region) based upon the selection of the first (County). I have found a piece of code that works on its own and have adapted to suit my needs - see below. However, when I drop it into my main page the javascript is not working. It's because of the formObject but I just don't know enough to resolve this! Furthermore, I need the textboxes the user has already completed in the form to retain their value once the javascript kicks in as the completed form will submit to a database. This piece of code is working well . . . . Code: <?php $link = mysql_connect('myhost', 'myusername', 'mypassword') or die('Could not connect: ' . mysql_error()); mysql_select_db('mydatabase') or die('Could not select database'); if(isset($_GET["County"]) && is_numeric($_GET["County"])) { $County = $_GET["County"]; } if(isset($_GET["Region"]) && is_numeric($_GET["Region"])) { $Region = $_GET["Region"]; } ?> <script language="JavaScript"> function autoSubmit() { var formObject = document.forms['theForm']; formObject.submit(); } </script> <form name="theForm" method="get"> <!-- County SELECTION BASED ON city VALUE --> <?php ?> <select name="County" onChange="autoSubmit();"> <option value=''</option> <?php //POPULATE DROP DOWN MENU WITH COUNTRIES FROM A GIVEN city $sql = "SELECT * FROM county_regions"; $counties = mysql_query($sql,$link); while($row = mysql_fetch_array($counties)) { echo ("<option value=\"$row[CountyID]\" " . ($County == $row["CountyID"]? " selected" : "") . ">$row[County]</option>"); } ?> </select> <?php ?> <br><br> <?php if($County!= null && is_numeric($County)) { ?> <select name="Region" onChange="autoSubmit();"> <?php //POPULATE DROP DOWN MENU WITH RegionS FROM A GIVEN city, County $sql = "SELECT * FROM county_regions WHERE CountyID = $County "; $Regions = mysql_query($sql,$link); while($row = mysql_fetch_array($Regions)) { echo ("<option value=\"$row[CountyID]\" " . ($Region == $row["CountyID"]? " selected" : "") . ">$row[Region]</option>"); } ?> </select> <?php } ?> What follows is my form where the javascript is not working - edited quite a bit to save on space! Code: <head> <script language="JavaScript"> function autoSubmit() { var formObject = document.forms['subform']; formObject.submit(); } </script> </head> <form enctype="multipart/form-data" method="post" action="add_attraction01.php" FORM NAME="FormName"> <input type="hidden" name="MAX_FILE_SIZE" value="32768" /> <label for="Business_name">Business Name</label> <input type="text" size="60" STYLE="color: #FFFFFF; font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: 12px; background-color: #72A4D2;" <id="Business_name" name="Business_name" maxlength=60/><font size="1" face="arial" color="red">Required field</font><br /> <label for="StreetAddress">Address</label> <input type="text" size="60" rows="2" id="StreetAddress" name="StreetAddress" maxlength=120/><font size="1" face="arial" color="red">Required field</font><br /> <label for="Town">Town</label> <input type="text" size="25" id="Town" name="Town" maxlength=25/><font size="1" face="arial" color="red">Required field</font><br /> <?php $link = mysql_connect('myhost', 'myusername', 'mypassword') or die('Could not connect: ' . mysql_error()); mysql_select_db('mydatabase') or die('Could not select database'); if(isset($_GET["County"]) && is_numeric($_GET["County"])) { $County = $_GET["County"]; } if(isset($_GET["Region"]) && is_numeric($_GET["Region"])) { $Region = $_GET["Region"]; } ?> <form name = "subform" method="get"> <select name="County" onChange="autoSubmit();"> <option value=''</option> <?php $sql = "SELECT * FROM county_regions"; $counties = mysql_query($sql,$link); while($row = mysql_fetch_array($counties)) { echo ("<option value=\"$row[CountyID]\" " . ($County == $row["CountyID"]? " selected" : "") . ">$row[County]</option>"); } ?> </select> <?php ?> <br><br> <?php if($County!= null && is_numeric($County)) { ?> <select name="Region" onChange="autoSubmit();"> <?php $sql = "SELECT * FROM county_regions WHERE CountyID = $County "; $Regions = mysql_query($sql,$link); while($row = mysql_fetch_array($Regions)) { echo ("<option value=\"$row[CountyID]\" " . ($Region == $row["CountyID"]? " selected" : "") . ">$row[Region]</option>"); } ?> </select> <?php } ?> <input type="text" size="20"id="Tel_No" name="Tel_No" maxlength=20 onkeypress="return isNumberKey(event)"/><font size="1" face="arial" color="red">Required field</font><br /> <br/> <input type="submit" value="Submit your attraction" name="submit" onclick="return BothFieldsIdenticalCaseSensitive();"/> </form> </body> </html> It's probably obvious to you guys!! Thanks in advance for your help. Hi I am trying to use stoutlabs content slider on my website. I have a dummy set up here www.mattbbell.com Instead of the numbered navigation i want to have text like home, bio, contact etc The demo can be download here http://stoutlabs.com/demos/class_sli..._slider_v2.zip with all files necessary to make the dummy website you see there... From what i can tell I have to edit the sl_slider_new.js file and make it call a list of divs that i name home, bio, contact I think this is the section i need to edit but i don't know much about javascript.... Code: // -- Number nav setup if(self.options.numNavActive == true){ //create numbered navigation boxes, and insert into the 'num_nav' ul) var numItem = new Element('li', {id: 'num'+i}); var numLink = new Element('a', { 'class': 'numbtn', 'html': (i+1) }); numItem.adopt(numLink); self.options.numNavHolder.adopt(numItem); self.numNav.push(numLink); numLink.set('morph', {duration: 100, transition: Fx.Transitions.linear, link: 'ignore'}); numLink.addEvents({ 'click' : function(){ self.numPress(i); }, 'mouseenter' : function() { this.setStyle('cursor', 'pointer'); } }); //set initial number to active state if(i == self.options.itemNum){ var initNum = self.numNav[i]; initNum.addClass('active'); } } //end if num nav 'active' }); }, thanks! I have a database script that returns dates in the following format: yyyy-mm-dd I have been using the following code to change this format to dd-mm-yyyy: Code: <script type="text/javascript"> var myString = "[[date]]"; var mySplitResult = myString.split("-");document.write(mySplitResult[2] + "/" + mySplitResult[1] + "/" + mySplitResult[0] ); </script> However, I now want to display the date in text format, e.g. 01-08-2009 would be displayed as 01 August 2009. Could anyone please let me know how I change the script to show this format? Many thanks in advance, Neil Can someone please help me generate a series of 13 digit numbers and output them to a text file. I'm really desperate here. Thanks guys. I'm creating a page that calculates a number depending on what value is inputted into a text field. I need to create some javascript that updates this new calculated value and outputs it next to the input field. Anytime the user changes the number, it recalculates the value. My calculation is currently being produced by PHP, however if I need to, I can create javascript as well to recalculate these numbers. My formulas for all 4 calculations are as follows: First: Inputted Value * 10 Second: Inputted Value * 20 Third: Inputted Value / 2 Fourth: Inputted Value * 2 Here is my code I'm working with: PHP Code: <?php session_start(); $username = $_SESSION['username']; include_once('inc/connect.php'); $credquery = mysql_query("SELECT * FROM userstats WHERE username='$username'"); $row = mysql_fetch_assoc($credquery); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $sitetobanner = $_POST['sitetobanner']; $sitetotext = $_POST['sitetotext']; $bannertotext = $_POST['bannertotext']; $texttobanner = $_POST['texttobanner']; if (isset($sitetobanner)){ $bannerimp = round($_POST['bannerimp']); if ($bannerimp > 1){ $s = "s"; } if ($bannerimp <= $credits){ $newcredits = $credits - $bannerimp; $newbannercredits = $bannerimp * 10; $totalbannercredits = $bannercredits + $newbannercredits; $updatebanner = mysql_query("UPDATE userstats SET credits='$newcredits', bannercredits='$totalbannercredits' WHERE username='$username'"); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $convertedbanner = "You converted ".$bannerimp." credit".$s." into ".$newbannercredits." banner impressions"; } else{ if ($credits>1){ $mycredits = $credits - 1;} $errorbanner = number_format($mycredits, 0, '.', ''); } } if (isset($sitetotext)){ $textimp = round($_POST['textimp']); if ($textimp > 1){ $s = "s"; } if ($textimp <= $credits){ $newcredits = $credits - $textimp; $newtextcredits = $textimp * 20; $totaltextcredits = $textcredits + $newtextcredits; $updatebanner = mysql_query("UPDATE userstats SET credits='$newcredits', textcredits='$totaltextcredits' WHERE username='$username'"); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $convertedtext = "You converted ".$textimp." credit".$s." into ".$newtextcredits." text ad impressions"; } else{ if ($credits>1){ $mycredits = $credits - 1;} $errortext = number_format($mycredits, 0, '.', ''); } } if (isset($texttobanner)){ $texttobannerimp = round($_POST['texttobannerimp']); if ($texttobannerimp > 1){ $s = "s"; } if ($texttobannerimp <= $textcredits){ if ($texttobannerimp>=2&&$texttobannerimp>""){ $newcredits = $textcredits - $texttobannerimp; $newbannercredits = $texttobannerimp / 2; $totalbannercredits = $bannercredits + $newbannercredits; $updatebanner = mysql_query("UPDATE userstats SET textcredits='$newcredits', bannercredits='$totalbannercredits' WHERE username='$username'"); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $convertedtextimp = "You converted ".$texttobannerimp." text ad impression".$s." into ".$newbannercredits." banner impressions"; } else{ $convertedtextimp = "You Hag"; } } else{ if ($textcredits>1){ $mycredits = $textcredits - 1;} $errortextimp = number_format($mycredits, 0, '.', ''); } } if (isset($bannertotext)){ $bannertotextimp = round($_POST['bannertotextimp']); if ($bannertotextimp > 1){ $s = "s"; } if ($bannertotextimp <= $bannercredits){ $newcredits = $bannercredits - $bannertotextimp; $newtextcredits = $bannertotextimp * 2; $totaltextcredits = $textcredits + $newtextcredits; $updatebanner = mysql_query("UPDATE userstats SET bannercredits='$newcredits', textcredits='$totaltextcredits' WHERE username='$username'"); $credits = $row['credits']; $bannercredits = $row['bannercredits']; $textcredits = $row['textcredits']; $convertedbannerimp = "You converted ".$bannertotextimp." banner impression".$s." into ".$newtextcredits." text impressions"; } else{ if ($bannercredits>1){ $mycredits = $bannercredits - 1;} $errorbannerimp = number_format($mycredits, 0, '.', ''); } } ?> <html> <head> <title>Convert Credits</title> <script type="text/javascript" language="javascript"> function inputLimiter(e,allow) { var AllowableCharacters = ''; if (allow == 'NumbersOnly'){AllowableCharacters='0123456789.';} var k; k=document.all?parseInt(e.keyCode): parseInt(e.which); if (k!=13 && k!=8 && k!=0){ if ((e.ctrlKey==false) && (e.altKey==false)) { return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1); } else { return true; } } else { return true; } } </script> </head> <body> <h1>Convert Credits</h1><br /> Credits: <?php echo $credits; ?><br /> Banner Impressions: <?php echo $bannercredits; ?><br /> Text Ad Impressions: <?php echo $textcredits; ?><br /> <form action="convert.php" method="POST"> <h3>Credits To Banner Impressions</h3> Convert <input type="text" name="bannerimp" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" value="<?php echo $errorbanner; ?>" onChange=""> credits into BLANK Banner Impressions! <input type="submit" name="sitetobanner" value="Convert"><br /> <?php echo $convertedbanner; ?> </form> <form action="convert.php" method="POST"> <h3>Credits To Text Ad Impressions</h3> Convert <input type="text" name="textimp" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" value="<?php echo $errortext; ?>"> credits into BLANK Text Ad Impressions! <input type="submit" name="sitetotext" value="Convert"><br /> <?php echo $convertedtext; ?> </form> <form action="convert.php" method="POST"> <h3>Text Ad To Banner Impressions</h3> Convert <input type="text" name="texttobannerimp" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" value="<?php echo $errortextimp; ?>"> Text Ad Impressions into BLANK Banner Impressions! <input type="submit" name="texttobanner" value="Convert"><br /> <?php echo $convertedtextimp; ?> </form> <form action="convert.php" method="POST"> <h3>Banner To Text Ad Impressions</h3> Convert <input type="text" name="bannertotextimp" id="NumbersOnly" onkeypress="return inputLimiter(event,'NumbersOnly')" value="<?php echo $errorbannerimp; ?>"> Banner Impressions into BLANK Text Ad Impressions! <input type="submit" name="bannertotext" value="Convert"><br /> <?php echo $convertedbannerimp; ?> </form> </body> </html> How do I reset selct lists like below. <form> <select size='4' STYLE='width: 164px' MULTIPLE id="num" name='num[]'> <option value='1' selected>1</option> <option value='2' selected>2 </option> <option value='3' selected>3</option> </select> <input type="button" name="reset" > </form> How can i get the below function to only select a value from the select list when there is an exact match. Let's say I type 54 in the text box it immediately selects 54921 value from the list? Code: <html> <head> <title>test</title> <script type="text/javascript"> function change_uids(uid){ var uids = document.getElementById("uids"); for (var i=0; i<uids.options.length; i++){ if (uids.options[i].value.substr(0,uid.value.length) == uid.value){ uids.options[i].selected = true; break; } } } </script> </head> <body> <form action="test.html" method="get"> <label for="uid">Your ID:</label><input type="text" id="uid" name="uid" onkeyup="change_uids(this)"/> <select id="uids" size="7" > <option value=""></option> <option value="12844">12844</option> <option value="54921">54921</option> <option value="54922">54922</option> <option value="25643">25643</option> <option value="61423">61423</option> <option value="43903">43903</option> <option value="58345">58345</option> <option value="61934">61934</option> </select> </form> </body> </html> Hello everyone, after a few days of looking i give up i just don't know what to look for or how to do it. on this website "http://www.hunlock.com/blogs/Everything_You_Ever_Needed_To_Know_About_Video_Embedding there is a section called How to make a video select list. I have been able to replicate and modify it to my liking how ever i have one issue. i can't make my videos fullscreen. The videos have and give the option for full screen but the fullscreen doesn't work. i prefer this kind of code because it allows my webpage to select a video without changing the webpage and play it, i find it much more smoother then then multiple embedded videos in tabs (i don't even know what to call it so thats what i call it) just incase the website doesnt work or something i will post the script first part<div id='videoPlayback' style='width: 435px; height:350px; background-color: #800000;'></div> then <div id='selectDemo1' style='display: none'> <object width="425" height="350"> <param name="movie" value="http://www.youtube.com/v/-is63goeBgc"></param> <param name="wmode" value="transparent"></param> <embed src="http://www.youtube.com/v/-is63goeBgc&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"> </embed> </object> </div> <div id='selectDemo2' style='display: none'> <object width="425" height="350"> <param name="movie" value="http://www.youtube.com/v/c6SHsF1n9Qw"></param> <param name="wmode" value="transparent"></param> <embed src="http://www.youtube.com/v/c6SHsF1n9Qw&autoplay=1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"> </embed> </object> </div> then <A HREF="#" onclick='return playVideo("selectDemo1","videoPlayback")'>RvD2: Ryan vs. Dorkman 2</A><BR> <A HREF="#" onclick='return playVideo("selectDemo2","videoPlayback")'>Beatboxing Flute </A><BR> and finally<script type="text/javascript"> function playVideo(sourceId, targetId) { if (typeof(sourceId)=='string') {sourceId=document.getElementById(sourceId);} if (typeof(targetId)=='string') {targetId=document.getElementById(targetId);} targetId.innerHTML=sourceId.innerHTML; return false; } </script> i'm not sure the exact functions or how to write this kinda stuff from scratch so if you have any helpfull additions or suggestions please let me know. I want to validate a select list that looks like the below select list. How can I do this when it is named "status[]". <select size='4' MULTIPLE name='status[]'> <option value='COMPLETE'>COMPLETE</option> <option value='ENTERED'>ENTERED</option> <option value='INSTALLED'>INSTALLED</option> </select> So I have the below form. How can I validate that if the user enters a quantity in the field they also must select a reason code. How can I do this.\ Code: <form name="theForm" onsubmit="validate()"> <table> <tr id='Child1'> <td><input type = 'text' MAXLENGTH='3' id='PROD_1_150.00_133.50' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> </select></td> <input type='hidden' value='4395' name='itemid[]' > </tr> <tr id='Child2'> <td><input type = 'text' MAXLENGTH='3' id='PROD_1_150.00_133.50' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> </select></td> <input type='hidden' value='4396' name='itemid[]' > </tr> <tr id='Child3'> <td><input type = 'text' MAXLENGTH='3' id='PROD_1_150.00_133.50' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> </select></td> <input type='hidden' value='4353' name='itemid[]' > </tr> <tr id='Child4'> <td><input type = 'text' MAXLENGTH='3' id='PROD_1_150.00_133.50' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'><option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> </select></td> <input type='hidden' value='4355' name='itemid[]' > </tr> </table> </form> I have html like this Code: <form> <select name="otype[]" class="txtText" id="otype[]"> <option value="Processing">Processing</option> <option value="Shipped">Shipped</option> </select> some code...... <select name="otype[]" class="txtText" id="otype[]"> <option value="Processing">Processing</option> <option value="Shipped">Shipped</option> </select> some code....... <select name="otype[]" class="txtText" id="otype[]"> <option value="Processing">Processing</option> <option value="Shipped">Shipped</option> </select> I need to change all select lists options to "Shipped" if admin clicks on "Shipped" on top of the page and "Processing" if customer clicks on "Processing" link (<a href="javascript:select_processing()">Processing</a>) Can somebody help me in doing so? Hi there, Is there any way in JS to convert all items in a Select to a numbered list? I can imagine something like Code: for (Scount=0;Scount<select.length;Scount++) and then process each value in the Select to a numbered list, but I can't figure out how and there seems to be no one on the internet with the same goal... Am quite a newbie! Thanks in advance for your help! Thomas the code below was got from <http://www.javascriptkit.com/javatutors/selectcontent2.shtml> I was following to tutorial to learn how to create multi-level select list in javascript. i have gone through it but wanted to print the individual selected item in each option, i could not. the first worked well for be because the selected options are manually typed, but the last option became difficult because they are dynamically loaded. Please can anyone guild me on how to print the selected option of the second field? <form name="classic"> <select name="countries" size="4" onChange="updatecities(this.selectedIndex)" style="width: 150px"> <option selected>Select A City</option> <option value="usa">USA</option> <option value="canada">Canada</option> <option value="uk">United Kingdom</option> </select> <select name="cities" size="4" style="width: 150px" onClick="alert(this.options[this.options.selectedIndex].value)"> </select> </form> <script type="text/javascript"> var countrieslist=document.classic.countries var citieslist=document.classic.cities var cities=new Array() cities[0]="" cities[1]=["New York|newyorkvalue", "Los Angeles|loangelesvalue", "Chicago|chicagovalue", "Houston|houstonvalue", "Austin|austinvalue"] cities[2]=["Vancouver|vancouvervalue", "Tonronto|torontovalue", "Montreal|montrealvalue", "Calgary|calgaryvalue"] cities[3]=["London|londonvalue", "Glasgow|glasgowsvalue", "Manchester|manchestervalue", "Edinburgh|edinburghvalue", "Birmingham|birminghamvalue"] function updatecities(selectedcitygroup){ citieslist.options.length=0 if (selectedcitygroup>0){ for (i=0; i<cities[selectedcitygroup].length; i++) citieslist.options[citieslist.options.length]=new Option(cities[selectedcitygroup][i].split("|")[0], cities[selectedcitygroup][i].split("|")[1]) } } </script> If i have a drop down list on my website, and i want to use javascript to change its selected value, however, i do not have the id/name attribute of the option i want to select, only have the "value" attribute of the option, can it be done? <select name="category"> <option value="">No Preference</option> <option value="Apples">Apples</option> <option value="Oranges">Oranges</option> <option value="Pears">Pears</option> <option value="Banana">Banana</option> </select> I imagine somehow.. selecting the options and looping through them and match the value. Really new to javascript, can anyone advise? Thanks in advance! I currently have two html select list boxes side by side on a form, two buttons in between the boxes to move items from list box to the other, and a javascript function to control the movement of the items from one box to the other. Here is the javascript: Code: function MoveSelected(from, to) { var lstFrom = $(from); var lstTo = $(to); for (var i = 0; i<lstFrom.length;i++) { if ( lstFrom[i].selected ) { var elOptNew = document.createElement('option'); elOptNew.text = lstFrom[i].text; elOptNew.value = lstFrom[i].value; try { lstTo.add(elOptNew, null); // standards compliant; doesn't work in IE } catch(ex) { lstTo.add(elOptNew); // IE only } } } for (var i = lstFrom.length-1; i>=0;i--) { if ( lstFrom[i].selected ) { lstFrom.options[i] = null; } } } Here are the two html form select list boxes (lstAvailProd is the starting list box that lists the initial data and lstSelectProd is the destination list box): Code: <td width="10%" valign="center"> <a href="javascript: MoveSelected('lstAvailProd','lstSelectProd');"><IMG SRC="buttons/right_arrow.gif" style="padding-bottom: 2px;" /></a><br /><br /> <a href="javascript: MoveSelected('lstSelectProd','lstAvailProd');"><IMG SRC="buttons/left_arrow.gif" /></a> </td> I was wondering if anyone could tell me how I could modify my code to allow for the selection of all the data in the starting list box by only selecting and moving the first item in the list to the destination list box? The first item is called "All Products", so instead of actually selecting every product in the starting list and moving them to the destination list, I would like the code to see that if the "All Products" list item is moved to the destination list, move all the other list items in the destination list back to the starting list. Here's an example of what the code for each list box looks like: Starting List Box: Code: <select name="lstAvailProd" id="lstAvailProd" multiple="true" size="8" style="width: 250px;"> <option value="-1">{All Products}</option> <option value="1">Product 1</option> <option value="2">Product 2</option> <option value="3">Product 3</option> <option value="4">Product 4</option> <option value="5">Product 5</option> </select> Destination List Box: Code: <select name="lstSelectProd" id="lstSelectProd" multiple="true" size="8" style="width: 250px;"> </select> Any help would be appreciated, thanks!! I have selectitem list which has name value pairs SelectItem(value, name), i need to iterate in JS and i need to populate in to option list, like below, but it dint work for me. Please any help function loadme(listVle){ // listVle is the List<SelectItem> var ele = document.getElementById('numadts'); for (var i=0;i<listVle.length;i++) { var elOpt = document.createElement('option'); var fldName = listVle.item(i).getAttribute('name'); // This line the problem is elOpt.text = fldName; elOpt.value = fldName; try { ele.add(elOpt, null); } catch(ex) { ele.add(elOpt); } } } and the HTML <BODY> <FORM> <select name="numadts" id="numadts" onclick="loadme()""> </select> </FORM> </BODY> |