JavaScript - Bold Lowercase Letters Only
I have a document list of several hundred drug names where some are lower case and some are all caps. I want to bold only the lower case drug names but don't want to do it manually. Is there a java script that I can apply where it automatically does that for me?
Similar TutorialsHi, just a quick question. Is it possible to make an array lowercase at all? or can you only do this with a string? Thanks. Hi there, I would like to sort the items regardless of uppercase/lowercase after moving them to another listbox. Here is my code, and I cannot figure out what is wrong with it. 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> <title>Untitled Page</title> <script language="javascript" type="text/javascript"> function MoveItem(unselectedLst, selectedLst) { var unselectedEmail = document.getElementById(unselectedLst); var selectedEmail = document.getElementById(selectedLst); var uValue = unselectedEmail.value; var sValue = selectedEmail.value; if ((uValue != null) && (sValue != null)) { if( unselectedEmail.options.selectedIndex >= 0 ) { var newOption = new Option(); // Create a new instance of ListItem newOption.text = unselectedEmail.options[unselectedEmail.options.selectedIndex].text; newOption.value = unselectedEmail.options[unselectedEmail.options.selectedIndex].value; selectedEmail.options[selectedEmail.length] = newOption; //Append the item in selectedEmail unselectedEmail.remove(unselectedEmail.options.selectedIndex); //Remove the item from unselectedEmail //sort items in listbox in alpha order arrTexts = new Array(); for(i=0; i<unselectedEmail.length; i++) { arrTexts[i] = unselectedEmail.options[i].text; } arrTexts.sort(); for(i=0; i<unselectedEmail.length; i++) { unselectedEmail.options[i].text = arrTexts[i]; unselectedEmail.options[i].value = arrTexts[i]; } //sort items in listbox in alpha order arrayTexts = new Array(); for(i=0; i<selectedEmail.length; i++) { arrayTexts[i] = selectedEmail.options[i].text; } arrayTexts.sort(); for(i=0; i<selectedEmail.length; i++) { selectedEmail.options[i].text = arrayTexts[i]; selectedEmail.options[i].value = arrayTexts[i]; } } } else { alert('Select Item From The List. '); } } </script> </head> <body> <table width="300"> <tr> <td> <select id="ListBox1" name="ListBox1" size="6"> <option>One</option> <option>Two</option> <option>Three</option> </select> </td> <td> <p> <input onclick="MoveItem('ListBox1', 'ListBox2');" type="button" value="->" /> </p> <p> <input onclick="MoveItem('ListBox2', 'ListBox1');" type="button" value="<-" /> </p> </td> <td> <select id="ListBox2" name="ListBox2" size="6"> <option>allalong@msn.com</option> <option>boys@hotmail.com</option> <option>cy@yahoo.com</option> <option>bread@hotmail.com</option> <option>eetApple@ymail.com</option> <option>applepie@gmail.com</option> </select> </td> </tr> </table> </body> </html> Hello. I have created a Bold button - when i click the button it applies it into my textarea. The Problem is if i want to apply the bold style only to a single line and the rest of the written text will be normal and not bold it doesn't work. How can I add to the function that when i select a certain line and click on the button to make it bold only the selected line will be bold?? This is the script : PHP Code: <script type="text/javascript"> function bold(id) { var element = document.getElementById(id); element.style.fontWeight = ( element.style.fontWeight == "bold" ) ? "normal" : "bold"; } </script> And this is the button : PHP Code: <img src="Bold.bmp"width="42" height="39" title="Bold Font" onclick="bold('bodytext')" style="cursor:pointer;" /> Hello, I wonder if you guys.girls would be kind enough to help me. I have some code, but I need to make the " Total price will be :$xx " text to be in bold. Here is the code I have atm Code: <script type=text/javascript> function getTotal(){ var form=document.theForm; var inputs=form.getElementsByTagName('input'); var length=inputs.length; var total='0'; for(i=0;i<length-1;i++){ if(inputs[i].type=='radio'){ var checked=inputs[i].checked?1:0; if(checked){ var value=inputs[i].value.split("~~")[0]; total-=-value; } } } document.getElementById('totalspan').innerHTML="Total price will be: $"+total total='0'; } </script> </html> Hi there, I would like to do the following: When I click on a button, it will set the item in the listbox to be bold. But this will only happen when the user clicks on the desired item to be bold and presses the button. An alert message will occur when he/she presses the button without clicking on the item, stating that the user will need to click on the item. How shoukld I do it in javascript? hi, i am trying to make my website so that when i click on a button it makes the selected text into bold or when i click another button it makes the selected text italic and finally when a thrid button is clicked it makes it underlined. i have tried searching for a way of doing this throught javascript but i cant seem to find any. any suggestions or examples on how i can achieve this would be much appreciated as i really need to get this working, thanks for any advice given Dear All, Here I am facing one issue, that I want to removing all html tags except BOLD,ITALIC,UNDERLINE & UL,LI. Means if my data is like, <b><i> Test Data </b></i> <input type="text" name="test"> <script> function test() { ............. } </script> Then I want the following output.... <b><i> Test Data </b></i> function test() { ............. } Means I need the data with tags BOLD,ITALIC,UNDERLINE & UL,LI not any else tags..... I have tried with this strInputCode.replace(/<[^>]+>/ig,""); but its removing all html tas that i dont want Hey everyone Okay so... I'm working on a site, which will include a registration form for users that wish to register. In this registration form I would like it to have an AJAX based effect, such that when the user types each letter out for his username in the field, his username will appear (letter upon letter) itself below, at the end of their unique url. To explain further:- Say I type my username to be Owen Below the field I would like it to display: http://www.mydomain.com/Owen http://Owen.mydomain.com/ As I type it. Is this possible? I've done my research, but had little luck. I'm sure it is possible as I've seen it before in a slightly different manner. Hope you can or are willing to help Thank you Owen Ayres Hi all, I'm trying to change our shopping cart code by making a small modification. When editing a product, there is a dimensions box which currently only allows numbers. We want it to allow numbers and letters (don't ask why). The code we have is the following which we think is related to why our shopping cart won't allow letters in the box. Could someone please edit the following code to allow letters? Thank you. Code: if(isNaN(dimensionsFormat(prodWidth.value)) && prodWidth.value != "" && !sellingDP) { ShowTab(0); alert("%%LNG_EnterWidth%%"); prodWidth.focus(); prodWidth.select(); return false; } if(isNaN(dimensionsFormat(prodHeight.value)) && prodHeight.value != "" && !sellingDP) { ShowTab(0); alert("%%LNG_EnterHeight%%"); prodHeight.focus(); prodHeight.select(); return false; } if(isNaN(dimensionsFormat(prodDepth.value)) && prodDepth.value != "" && !sellingDP) { ShowTab(0); alert("%%LNG_EnterDepth%%"); prodDepth.focus(); prodDepth.select(); return false; } I am trying to make a JavaScript chat-bot I was using this to answer a month questions and it worked fine for what is the month after DatesA=new Array("january,February","february,March","march,April","april,May","may,June","june,July","july,Aug ust","august,September","september,October","october,November","november,December","december,January "); if (input.search("what is the next month after")!= -1) {document.result.result.value = "Sorry, I don't know."; for (i=0; i<DatesA.length; i++) { Date=DatesA[i].split('='); if (input.search(Date[0]) != -1) { document.result.result.value = Date[1];} } return true;} What is the month after May answer: June however it didn't with letters. Is there a way to write this to prevent the wrong single letter and small words from triggering Letterbefore=newArray("b=a","c=b","d=c","e=d","f=e","g=f","h=g","i=h","j=i","k=j","l=k","m=l","n=m", "o=n","p=o","q=p","r=q","s=r","t=s","u=t","v=u","w=v","x=w","y=x","z=y"); Then use this: if (input.search("what is the letter before")!= -1 || input.search("what letter comes before")!= -1) {document.result.result.value = "Sorry."; for (i=0; i<Letterbefore.length; i++) { Letter=Letterbefore[i].split('='); if (input.search(Letter[0]) != -1) { document.result.result.value = Letter[1];} } return true;} . The bot correctly answers for x y and z . It then answers V for all other letters, digits and short words What is the letter before cow answer: V Thank you for your time I'm working on a script to check password strength "onkeyup",so when the user enters a password after every character i call a function to check the passwords strength.I'm almost ready,but i stucked with one thing: I want to check the same characters in the password,so i can deduct some point from the score if there are identical characters. Here is my code: PHP Code: var multis = 0; for(var x = 1; x < passLength; x++) { actChar = new RegExp(password.charAt(x),"g"); multis += password.match(actChar).length; } I know it seems an easy task,but i've spent at least 6 hours with it,(the first pitfall was that i didn't know the RegExp function and took my variables into the match() function,i think you can imagine the results)and i just can't figure this out,i always get crazy results,i've tried a few more versions as well without any luck. Thx in advance for anybody who can help me! Hi wise javascript gurus, I am working on a small form that on the click of a button, it calls a function to validate a string that consists of 3 portions delimited with a dash("-") in the following format XXX-NNNN-XXX where X are letters only where N are numbers only I have to use regular expressions to validate the first portion and verify that its exactly 3 characters long that are letters only if the first portion or "plant code" is larger then 3 characters long an alert gets display also if the first portion contains alphanumeric or numeric characters an alert gets displayed, the first portion has to be in letters only. down below is my code that is not functional at the time because I know for sure the way I check for regular expressions is a bet washy but thats the only thing I was able to come up with, any help will be appreciated. thanks for making time to read my thread Code: <html> <head> <script type="text/javascript"> function validateit() { var number = document.myform.product_number.value; var charnum = number.length; if (number =="") alert("you must enter a product number, field cannot be empty"); else if (charnum < 12 || charnum > 12) alert("the product numbre has to be exactly 12 characters long"); else validate_number(number); } function validate_number(num) { var objRegEx = /^[a-z]+$/; split=num.split("-",3); if (split[0].length!=3) alert("the Plant Code portion of the Product Number has to be only three charactes long") if!(objRegEx.test(split[0]) alert("the Plant Code portion of the Product Number has to be letters only") } </script> <title>waldo's</title> <style type="text/css"> .heading{font-weigth:bold;text-align:center; font-family:"comic sans MS"} </style> </head> <body><form name="myform"> <table align="center" border="1" width="55%"> <caption style="font-family:'comic sans MS';font-size:26pt"> Waldos's WareHouse</caption> <tr class="heading"><td>Product Number</td><td>Plant Code</td><td>Production Run</td><td>Shift Number</td></tr> <tr><td><input type="text" name="product_number"></td><td><input type="text" name="plant_code" readonly></td><td><input type="text" name="production_run" readonly></td><td><input type="text" name="shift" readonly></td></tr> <tr><td><input type="button" value="Check Validity" onclick="validateit()"/></td><td align="right">Validation Date:</td><td colspan="2"><input type"text" size="47" readonly></td></tr> </table></form> </body> </html> Hi, I have an array which is populated by a count of instances from another array, so its ends up with data like: msg = [2 x this event, 5 x that event, 17 x another event, 22 x something else] I need to sort this by the number before the 'x'. At present, a .sort() would put 1 - 9 before anything greater than 10, obviously not what I'm after. How can I make it put this array into the correct order (e.g 22 x something else, 17 x another event, 5 x that event, 2 x this event) Thanks! Ic. Hi, I'm very new to javascript, and I'm working on a simple script that will allow me to take a string of numbers, and convert it to a word. For example: I type 00010203 into a box, and it would return abcd. I've got the above to work, however..I'd like to add a couple special characters so that when the user types in a string that contains "32" it will return a ' ' (space). For example: 000102033200010203 would return 'abcd abcd' Here's my code, as of now: Code: <script type="text/javascript"> function show_prompt() { var s = prompt("Please enter a string of numbers"); for (i = 0; i <=s.length; i = i+2) { var t = s.slice(i,i+2) var n = parseInt(t,10) + 97 document.write (String.fromCharCode(n)) } } </script> hi everybody, i'm using this function to allow only numbers to be written in a textbox, however i want to allow lowercase "a" and "b" also with the numbers.. is it possible with this function? Code: <script type="text/javascript"> function rakamkontrol2(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } </script> </head> <body> <input type='text' id='gostergesayfa' size="3" onkeypress="return rakamkontrol2(event)"/> Hi all, Forgive my ignorance, I'm quite new to Javascript... I'm looking to do two things: the first is to move elements of an array to the next index using a function. I have managed to do this like so: Code: var letters = ['h','i','j','k']; function moveElements(anArray){ var newArray = anArray; newArray.unshift(newArray[newArray.length-1]); newArray.pop(); } moveElements(letters); (this may or not be great, but it seemed to work) ... but I want the original array to reset to its original state if the function is called again (thus producing the same answer as opposed to shifting the elements again). Secondly, and this is the bit I'm really struggling with: I want to compare each letter of a string to elements within an array and display the indices. For instance: Code: var myArray = ['a', 'b', 'c', 'd', 'e', 'f']; var text = 'dead'; Hence I want the result '3,4,0,3'. I know the answer will use for and if statements but I can't wrap my head around it at all. Help would be appreciated, thank you. Hey I'm trying to make a script which will check if the string which the user sent from a form contains ONLY letters. The problem is if the user entered something like this "25 years old" it allow that to be submitted. It only blocks submissions of the form if the user submits NO letters like this "12345". I want it to block submissions if at least one character isn't a letter. Here's my code: Code: var message = document.myform.formtest.value; var allowed = /[A-z+]/; if(!allowed.test(message)) { alert("The field only allows letters (a-z)."); return false; } Hi, can anyone tell me how to detect any word (a-z only, surrounded by whitespace) less than 5 letters long? Edit - this is what I have currently: Code: var RE=/\s([a-z]{1,4})\s/gi; var string="some words"; //should be turned to "words" string=string.replace(RE, ""); This is taking 4 letter chunks from the end of words. Cheers, Gus Edit - fixed (replaced \s with \b) -------------------------------------------------------------------------------- Can some1 help me at this, i am very new to javsciprt and HTML things, so as the title says, a simple bold to the selected text in a div is what i need. below is the div area i have, so how do it?? Code: <TD colspan="25" width="525px" style="text-overflow: ellipsis; overflow: hidden;"> <input type="hidden" $acmForms.bindText("casecomments") /> <div #if (!$acmForms.getFormAttributes().isReadOnly()) CONTENTEDITABLE #end onKeyUp="dairy_limitTextArea(this, 4000)" onKeyDown="dairy_limitTextArea(this, 4000)" id="spell_casecomments" style="width:800px; height:220px; overflow: auto; border: 1px solid #bdcee5;"> </TD> |