JavaScript - Text Box Duplicated Numbers Error Does Not Work 100%
Similar Tutorialshi 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 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> Hi Im alot stuck at the moment so if anyone can help resolve the issues i'm having I would be very grateful! if you go to http://love2-create.com and click on the orange "view profile" link about halfway down the left hand column, a tab opens showing a profile with a small picture gallery at the bottom, this gallery works fine in firefox and google chrome, however in safari it works sometimes but not always and in IE it usually works on the first time the page is loaded but then when the page is refreshed and the profile link is clicked I get an Error: 'document.getElementById(...)' is null or not an object on line 60, the lines in question look like this: Code: buildcontentdivs:function(setting){ var alldivs=document.getElementById(setting.id).getElementsByTagName("div") for (var i=0; i<alldivs.length; i++){ if (this.css(alldivs[i], "contentdiv", "check")){ //check for DIVs with class "contentdiv" setting.contentdivs.push(alldivs[i]) alldivs[i].style.display="none" //collapse all content DIVs to begin with } } }, Does anyone know why this may be, and how it can possibly work sometimes but not always?? its totally got me baffled so if anyone can help I would very very much appreciate it, please let me know if you need any other details about the site etc from me. Regards, Keir Hi, For the life of me I can't work out what is wrong with the code he http://www.spencercarpenter.co.uk/po...162&fgh=showMe I know it is somthing to do with the url and that it is a synax error but I really am stuck as I cant see what it is. If anyone could help me resolve this I would be very grateful. Thanks for any help. Spencer Im trying to run some jquery on my website but when i try and use them i get this following error in IE8 Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET CLR 3.0.04506; Media Center PC 5.0; SLCC1; InfoPath.2) Timestamp: Fri, 14 May 2010 18:37:55 UTC Message: Permission denied Line: 19 Char: 25131 Code: 0 URI: http://runningprofiles.com/members/s.../jquery.min.js I got no errors in FF but nothing works.... The webite that the code is on is he http://runningprofiles.com/members/s...ll_Script.php# any help would be great I have always loved the way the text boxes work for comments on Deviantart: http://www.deviantart.com/#/d37kh7x That is just a picture I chose at random. Underneath the picture, it says "Add a Comment" and there is a textbox. When you click inside it, the textbox expands. There is also a speech bubble coming from the lefthand side of the textbox? HOW THE HECK ARE THESE DONE??? It looks so clean and pretty. I think it's a Javascript thing. When I save the page to my computer to start messing around with the code, the textbox does not expand, and the speech bubble does not come from the lefthand side of the textbox. So i can't play with the code to try to figure it out myself. Why doesn't the feature work when I save the page to my desktop? if you visit my site: http://site-tonight.com/works you will notice if you click the image, the Colorbox comes up with a new image, BUT if you click the word Details below the image, the colorbox effect does not take place, even though it using the same link as the image. is there a way to make that text link be clicked and have an image pop up in the colorbox style? thanks much, kyle I'm fairly new to JS so sorry in advance if this is a stupid question! I have a textarea which uses ckeditor to make it a wysiwyg. I also have a bit of JS which watches the ckeditor and when a user types into it, whatever they type appears in a div elsewhere on the page. My ckeditor allows the text to be bold, italic, underlined and resized. When I apply styles to the text in the ckeditor textarea, I want them to reflected in the div which updates. At the moment only underline and resizing the text works. Choosing bold or italic does nothing the text updates ok, but no bold or italic. I've been told: "Ckeditor is using strong for bold, em for italics. My guess is that the browser or framework you are using doesn't apply bold and italics styles to those tags. You'll have to do that yourself." I've tested on several browsers, I checked in FF Opera Safari Chrome IE8 & IE9 and its the same in all them. Underline works, resize works but neither bold or italic do. (Interestingly in IE7 bold and italic do work as well as the size and underline! What's going on with that?!?) So I assume it is the framework? Can anyone tell me if this is right and if so, how do I go about doing that myself? heres the JS I'm using to update the div: Code: <label for="editor1">Background Story</label> <textarea id="editor1" name="editor1">This is sample text</textarea> <div id="story"></div> <script type="text/javascript"> CKEDITOR.replace( 'editor1' ); timer = setInterval('updateDiv()',100); function updateDiv(){ var editorText = CKEDITOR.instances.editor1.getData(); $('#story').html(editorText); }</script> Hello everyone. I hope I'm posting this in the right place. I'm using the Disco Background Effect script found here that causes the background color of the page to continuously change. For my design I need other aspects of the page to change along with it. Such as some title Text and HR lines. Is it possible to call this script to work on other things such as images, text and HR lines? In other words I want some text to change color in time with the background changing. I appreciate any help you might have. Ron Hello I have this snippet for controlling the number of characters entered in a textarea. It works. But, if I replace in this code the name "my_form" by "contact-form" and "my_text" by "message", it doesnt ! It looks like the keyword is " my_form ". You change that , and the script will not work! It turns out that I have to change those names because the form as it was already had those names my_form and message before I added this counter And I dont want to replace the names of the form in order to adapt them to this code snippet below. The question is why would the script not work if I have just replaced two words, which dont seem to be keywords of JS programming (my_form and my_text) <html><head> <title>(Type a title for your page here)</title> <script language=JavaScript> <!-- function check_length(my_form) { maxLen = 50; // max number of characters allowed if (my_form.my_text.value.length >= maxLen) { // Alert message if maximum limit is reached. // If required Alert can be removed. var msg = "You have reached your maximum limit of characters allowed"; alert(msg); // Reached the Maximum length so trim the textarea my_form.my_text.value = my_form.my_text.value.substring(0, maxLen); } else{ // Maximum length not reached so update the value of my_text counter my_form.text_num.value = maxLen - my_form.my_text.value.length;} } //--> </script> </head> <body> <form name=my_form method=post> <textarea onKeyPress=check_length(this.form); onKeyDown=check_length(this.form); name=my_text rows=4 cols=30></textarea> <br> <input size=1 value=50 name=text_num> Characters Left </form> </body> </html> Hi I have written the following code to read contents of a text file using FileReader object of HTML 5 for Google Chrome. Quote: <script> function handle_files(files) { var i; if (checkBrowser("Chrome")) { for (i = 0; i < files.length; i++) { file = files[i]; var reader = new FileReader(); ret = []; reader.onload = function (e) { console.log(e.target.result) } reader.onerror = function (stuff) { console.log("error", stuff) console.log(stuff.getMessage()) } text = reader.readAsText(file[i]); alert(text); } } } </script> ---------------------- <input type="file" multiple="multiple" onchange="handle_files(this.files)"> Unfortunately, the variable text always displays as undefined. Everything above the line text = reader.readAsText(file[0]); works fine. How can I fix it?. Or is there any other solution to read a text file using HTML5/JavaScript on Chrome? Thanks in advance. Code: <html> <title> random!!</title> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="jquery.min.js"></script> </head> <body> <div class="one" style="cursor: pointer;"> type1<br/><br/></div><div class="two" style="cursor: pointer;">type2<br/><br/></div><div class="three" style="cursor: pointer;">type3<br/><br/></div> <div class="oneone">atrdjgkhgfyfygfykfyfkygfvkgvkhgv</div><div class="twotwo">hgfihygohgohsgoihgolhgshgoshdgchchj</div><div class="threethree">siucgdiuhsbcohbscjbsidjcksjdnck</div> <script type="text/javascript"> $(document).ready(function() { $('div.twotwo').hide(); $('div.threethree').hide(); $('div.one').toggle(function() { $('div.twotwo').hide(); $('div.threethree').hide(); $('div.oneone').fadeIn('slow'); }, function() { return false; }); $('div.two').toggle(function() { $('div.oneone').hide(); $('div.threethree').hide(); $('div.twotwo').fadeIn('slow'); }, function() { return false; }); $('div.three').toggle(function() { $('div.twotwo').hide(); $('div.oneone').hide(); $('div.threethree').fadeIn('slow'); }, function() { return false; }); }); </script> </body> </html> The following code works perfectly when clicked once in each of the sub divisions(type1, type2, type3) for hide/show. But from the next time onwards we will have to click twice to initiate the hide/show. Can anyone suggest changes to make the code work as desired??.. P.S: sorry if i have made any stupid mistake.. i am quite new to this!! well the jquery is working fine for twitter and other stuff but its not working for facebook, when i highlight the text and select fb to share at then the facebook share just show the meta description of site and not the selected area. I am not able to understand where am i going wrong, any assistance provided is highly appreciated. Go to this link http://www.blobh.com/2011/09/testing-1.html there select some text then a tooltip kind of thing will appear first share at twitter then at facebook you will understand the matter. the script i am using is this Code: <script type='text/javascript'> $('.demo1').selectedTextSharer({ lists:"Twitter,http://twitter.com/home?status=%ts ,favicon|Facebook,http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.blobh.com%2F&t=%s,favicon|Wikipedia (en),http://en.wikipedia.org/w/index.php?title=Special:Search&search=%s,favicon|Google Maps,http://maps.google.com/?q=%s,favicon", extraClass: 'dark', title: 'Share this text ...', borderColor: '#7F241C', background : '#4F663A', titleColor : '#7F241C', textColor : '#FFFFFF', hoverColor: '#7F241C' }); </script> and the other script is this one http://bloghuts.googlecode.com/files...-sharer.min.js and the html is like this Code: <!-- Just wrap a text with a div and add a class, thats all ! --> <div class="demo1"> Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it</div> <textarea class="demo4"></textarea> <input class="demo4" type="text" /> Hay! I have a silly question, I have a row of numbers, 1 to 250. The numbers are all in one horizantal line. But I want to use a <br> after every 10 numbers. I tried: if(i % 10) { document.write("<br>"); } This is how I wanted to be: 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, Does any one know how can I achieve this I'm still a noob. I have written below code to except only number in a textbox. This is working fine. However, When I'm copying and pasting, then it is taking non-numbers. Code: <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <SCRIPT type="text/javascript"> function isNumberKey1(evt) { var charCode = (evt.which) ? evt.which : event.keyCode if (charCode = 46 && charCode > 31 && (charCode < 48 || charCode > 57)) return false; return true; } </SCRIPT> </head> <body> Phone number : <input type="text" id="phonenumber" onkeypress="return isNumberKey1(event)" maxlength="10" size="15" > <br /> <br /> Alternative number: <input type="text" onkeypress="return isNumberKey1(event)" id="alt" maxlength="10" size="15"> <input type="button" value="Submit"> </body> </html> I'm trying to teach myself Javascript to prepare for it next term. I asked earlier how to add together the numbers 1-10 in a loop. Now I'm wondering how can I change the 10 to be a valuable I input. Basically I want to be able to enter a number on the page or in a message box then I want the code to add all the numbers from 1- the number I enter. The code I got from my previous thread is he Code: <html> <head> <script type="text/javascript"> var varX = user input; function sum() { var varX = user input; for(varY = 1; varY<=10; varY++) { varX = varX + varY; } return varX; } var resultat = sum(); alert(resultat); // show message box with result </script> </head> <body> </body> </html> say cutcost2 is 10 and qty is 25 Code: document.profile_quote.cuttotal.value = eval(document.profile_quote.cutcost2.value + document.profile_quote.qty.value) .toFixed(2) the output i get is 1025 rather than 35. what have i got wrong? thanks |