JavaScript - Function To Prevent Numbers & @ Sign
Hello all,
Please I need help, I have a php form with different fileds. I have a field called description. The description field should only contains pure text, no numbers, but my users are entering phone numbers and email addresses into this field despite to the fact that there is already dedicated fileds for email and phone. What I want is a javascript funtion or php function that will automatically delete the numbers or @ from the field or prevent entering numbers and @ signs on this particular field. Many thanks in advance for your help. Similar TutorialsI've been messing with this code for about a couple of hours, and I did everything down to the wire..yet still I am unable to get it to work. When I input the numbers, and click off to the side nothing appears down at the final textarea of the form which is suppose to show the average. I've tried just about everything, sadly all I have to go by is other example codes, and the very intricate instructions which states I must pass the values to the calcAvg() to the second function of performCalc(), which I did, and then I assigned the var calcResult another value. From there I did the return..and after that I'm rather loss as to what to do next to get this code to work, any tips? 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>Calculation Average</title> <script type="text/html"> /* <![CDATA[ */ function calcAvg() { var calcResult=document.numbers.number1.value + document.numbers.number2.value +document.numbers.number3.value + document.numbers.number4.value + document.numbers.number5.value } function performCalc() { var calcResult = calcResult / 5 return calcResult; } /* This is what I got so far, as you can see I need plenty of help!*/ </script> </head> <H1> Calculate Average of Numbers</H1> <body> <form action="" name="numbers"> <table> <tr> <td> <tr> <td>Enter the five numbers:<br /> </td></tr> <tr><td> <input type="text" name="number1" size="3" onchange="calcAvg()" text="0" /></td> </tr> <tr> <td> <input type="text" name="number2" size="3" onchange="calcAvg()" text="0" /></td> </tr> <tr> <td> <input type="text" name="number3" size="3" onchange="calcAvg()" text="0" /></td> </tr> <tr> <td> <input type="text" name="number4" size="3" onchange="calcAvg()" text="0" /></td> </tr> <tr> <td> <input type="text" name="number5" size="3" onchange="calcAvg()" text="0" /></td> </tr> </table> </form> <form action="" name="averageResult"> <p> Estimate average: <input type="text" name="average" size="5" style="border-style: none; border-color: inherit; border-width: medium; background-color: Transparent" text="0" /></p> </form> </body> </html> So how do add a dollar sign the the front of total?? Code: total = round_decimals(order_total, 2) total = "$" + total; I really don't know what I am doing, but I need to know how to alter this script to load this website without having to click "Weathersentry online". I would like to double click on the icon the code is attached to and it sign in automatically. Can anyone help? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Sample Signin link WeatherSentry Online</title> </head> <body> <form id="DTNSigninForm" action="http://weather.dtn.com/dtnweather/common/signin.do" style="margin: 0,0,0,0;" > <a onclick='document.getElementById("DTNSigninForm").submit();return false;' href="javascript:void(0);">WeatherSentry Online</a> <input type="hidden" name="username" value="username" /> <input type="hidden" name="password" value="password" /> <input type="hidden" name="autoLogin" value="true" /> </form> </body> </html> hi. i know php but learning javascript. can anybody give me a reason why i might not wanna use the php practice of beginning every variable_name with a dollar-sign: $variable_name??? i am just accustomed to seeing my variables beginning with a dollar_sign. Thanks. I almost got part of this one program to work. It is of a golf sign with a golf ball moving across and landing in the word Golf into the "o" When the ball lands in the o the sign of "your online source of golf equipment" appears after ball has landed and grows in size. right now the ball is what I have but I can not get my sign to appear. I use 2 external files I will post all the coding here here is my main file I worked on this is my golfpage.htm file Code: <html> <head> <!-- New Perspectives on JavaScript Tutorial 4 Case Problem 1 The Golf Page Author: Date: 05 December 2010 Filename: golfpage.htm Supporting files: ball.gif, clouds.jpg, golf.js, golfer.gif, styles.css --> <title>The Golf Page</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <script src="golf.js" type="text/javascript"></script> <script type="text/javascript"> var x = new Array(-395, -389, -383, -377, -371, -365, -359, -353, -346, -340, -334, -328, -322, -316, -310, -304, -297, -291, -285, -279, -273, -267, -261, -255, -248, -242, -236, -230, -224, -218, -212, -206, -199, -193, -187, -181, -175, -169, -163, -157, -150, -144, -138, -132, -126, -120, -114, -108, -101, -95, -93, -91, -88, -86, -83, -81, -78, -76, -73, -71, -69, -66, -64, -61, -59, -56, -54, -51, -49, -47, -44, -42, -39, -37, -34, -32, -29, -27, -24, -22, -20, -17, -15, -12, -10, -7, -5, -2, 0); var y = new Array(-300, -300, -300, -299, -298, -297, -296, -294, -292, -290, -288, -285, -282, -279, -276, -272, -268, -264, -260, -255, -250, -245, -240, -234, -228, -222, -216, -209, -202, -195, -188, -180, -172, -164, -156, -147, -138, -129, -120, -110, -100, -90, -80, -69, -58, -47, -36, -24, -12, 0, -5, -10, -14, -18, -22, -25, -29, -32, -34, -37, -39, -41, -43, -45, -46, -47, -48, -48, -48, -48, -48, -48, -47, -46, -45, -43, -42, -40, -37, -35, -32, -29, -26, -23, -19, -15, -11, -6, 0); var index=0; var lastindex=x.length-1; // var fs=getFontSize("slogan"); function moveBall() { if (index <= lastindex) { placeIt("Ball", x[index], y[index]); index++; setTimeout("moveBall()", 5); } else { setFontSize("slogan", 25); } } </script> </head> <body onload="moveBall()"> <div id="Golfer" ><img src="golfer.gif" width="40px" alt="" /></div> <div id="Title"> THE G<div style="display: inline; position: relative; background-color: black;" ><img id="Ball" src="ball.gif" alt="O" /></div>LF PAGE </div> <div id="box" style=""> <span id="slogan"> Your Online Source of Golf Equipment </span> </div> </body> </html> Here is one external file where I made some functions this is the golf.js file Code: New Perspectives on JavaScript Tutorial 4 Case Problem 1 The Golf Page Name: Date: 05 december 2010 Function List: placeIt(id, x, y) Places the id object at the coordinates (x, y) showIt(id) Shows the id object by setting the object visibility to "visible" getFontSize(id) Retrieves the font size of the id object setFontSize(id, fs) Sets the font size of the id object to fs changeFontSize(id, dfs) Changes the font size of the id object by dfs */ function showIt(id) { object=document.getElementById(id); object.style.visibility="visible"; } function placeIt(id, x, y) { // Places the id object at the coordinates (x,y) object = document.getElementById(id); object.style.left = x + "px"; object.style.top = y + "px"; } function getFontSize(id) { // Returns the font size of the object with the value id object = document.getElementById(id); size = parseInt(object.style.fontSize); return (size); } function setFontSize(id, ptsize) { // Sets the font size of the object with the value id object = document.getElementById(id); object.style.fontSize = ptsize + "pt"; } function changeFontSize(id, dfs) { // Returns the font size of the object with the value id fs = getFontSize(id); setFontSize(id, fs + dfs); } Here is the styles.css page Code: /* New Perspectives on JavaScript Tutorial 4 Case Problem 1 Filename: styles.css This file contains styles used in the golfpage.htm file */ body {font-family:Arial, Helvetica, sans-serif; font-size: 18pt; color:blue; background-image: url(clouds.jpg)} #Title {position: absolute; left:395px; top:260px} #Ball {position:relative; top:0px; left:0px} #Ball img {border-width: 0px} #box {width:600px; height: 250px; border-style:solid; border-width:1 4 4 1; border-color:blue; background-color:rgb(0,255,0); text-align: center} #slogan {visibility: hidden; position: relative; top: 50px; color:black; font-family: Times New Roman, Times, serif; font-style:italic; font-weight:bold} What i am not able to get work i think is to call the changeFontSize() function to increase the size of the "sign" also an if statement to test value of fs variable is less then equal to 20 how do i get my sign to appear on the output? thanks Hello! Looking for some help/advice please. Imagine a wife has signed on to a web site in a browser tab. She does not sign off and walks away to do something else. Her husband sits at the computer and seeing her signed on, opens a new tab and tries to sign on to the same site. I am trying to write a script that will close other tabs/windows when the husband goes to the same site to sign on. So, on the sign on page (or even better, the sign off page), when the sign on button is clicked, a piece of Javascript code is run first. The javascript simply goes through all tabs on the browser, and checks to see if any such tabs has an HTML document that came from the same domain as the sign on page. If such tabs exist, then before POSTing the user name and password to the server, the Javascript code will close those tabs that contain HTML documents came from the same domain. So, I understand I need to set the window.name to a specific value. But does anyone know what the code on the sign on/sign off page to close the other tabs/windows would look like? Thanks so much for any and all help. Hi there, I would like to allow the "+" sign in my 3 textboxes. When the user does not put the "+" sign in the textboxes, and it is being validated, the system will allow it to pass. Also, it must check that it has at least 8 digits. 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> <link rel="stylesheet" type="text/css" href="CSS files/specialAlignment.css" /> <link rel="stylesheet" type="text/css" href="CSS files/externalCSS.css"/> <script language = "javascript" type = "text/javascript"> function check() { var fields = new Array("Office Telephone", "Mobile Telephone","Fax Number"); var telnr = /(^[\+]?[\d]{8,20}$)/; var index = new Array(); for(var i = 0; i < fields.length; i++) { var arrayFields = document.getElementsByName(fields[i]); for(var j = 0; j < arrayFields.length; j++) if(!(arrayFields[j].value) == "") { arrayFields[j].className = "defaultColor"; } else { arrayFields[j].className ="changeToRed"; index.push(fields[i]); } } if(index != 0) { joinComma = index.join(', '); alert('The field(s) corresponding to '+ joinComma + ' is/are not filled in.'); } } function noSpace(e, dec) { var key; var keychar; if (window.event) { key = window.event.keyCode; } else if (e) { key = e.which; } else { return true; } keychar = String.fromCharCode(key); if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) /*|| (key==107)*/) { return true; } else if ((("0123456789").indexOf(keychar) > -1)&& check(telnr.test(tfld))) { return true; } else if (dec && (keychar == ".")) { return true; } else return false; } </script> </head> <body> <label> *Office Telephone:</label> <input id="Text16" type="text" name="Office Telephone" onkeydown="return noSpace(event)" /> <br /> <br /> <label> *Mobile Telephone:</label> <input id="Text17" type="text" name="Mobile Telephone" onkeydown="return noSpace(event)" /><br /> <br /> <label> *Fax Number:</label> <input id="Text18" type="text" name="Fax Number" onkeydown="return noSpace(event)" /> <br /> <br /> <input id="Submit17" type="submit" value="Submit" onclick="return check()"/> </body> </html> Hello, Is there anyway to prevent images, words, divisions, etc from being selected? Also if something is selected is there a way to deselect? Thanks! Hello. I'm using the keyup event for an input box to check for the Escape key (keyCode 27). I'm then using this to hide a related select element. It works okay apart from IE(8) of course . How can I prevent IE carrying on with its normal Escape behaviour? If tried a number of things, most recently: Code: e.cancelBubble = true; if ( e.stopPropagation ) e.stopPropagation(); return false; but it, IE, is insistant. I tried switching to 'keydown' but it went a bit wonky.. Andy. I retrieve a list of links from a database using ajax, then I assign them to the innerHTML property of a div whose display property is set to "none" Then I set the display property to "display" to get a drop-down listbox. The problem is the links in the list are all hilighted like they've been dragged over by a mouse. How do I prevent these links from highlighting? I have a tracking ad at the bottom of my site. (no iframes). how do I know and/or prevent that tracking ad from popping up a popup? They are not suppose to, but I suspect they do. Is there a way to track this, or perhaps prevent them from popping the popup from within my page? I have access to various libraries, prototype/jquery etc.. so if there is a func/method in those, I could use too. Hey! I searched a while on the web for this but i didn't find a solution that really worked. So is there a way how i can prevent IE9 from scrolling when i use the arrow keys? Code: 1 ,<input id="14sq-und-0-value" size="12" maxlength="10" class="form-text" type="text"> 2 ,<input id="510sq-und-0-value" size="12" maxlength="10" class="form-text" type="text"> 3 ,<input id="1119sq-und-0-value" size="12" maxlength="10" class="form-text" type="text"> 4, <input id="20jsq-und-0-value" size="12" maxlength="10" class="form-text" type="text"> 5 ,<input id="oneyear-und-0-value" maxlength="10" class="form-text" type="text"> 6 ,<input id="twoyear-und-0-value" maxlength="10" class="form-text" type="text"> 7 ,<input id="threeyear-und-0-value" size="12" maxlength="10" class="form-text" type="text"> 8 <input id="vpssq-und-0-value" size="12" maxlength="10" class="form-text" type="text"> 9 <input id="500zh-und-0-value" size="12" maxlength="10" class="form-text" type="text"> 10 <input id="1000zh-und-0-value" size="12" maxlength="10" class="form-text" type="text"> 11 <input id="1500zh-und-0-value" size="12" maxlength="10" class="form-text" type="text"> now, i want to do, if the editor type content to 1, 2, 3 4 input box and finished namely the 1 ,2,3 4have value , then he can't type anything to the rest. if the 5,6,7, input box has value. then can't type anything to the rest. if the 8, input box has value. then can't type anything to the rest. if the9,10,11, input box has value. then can't type anything to the rest. How do I prevent my Link from disappearing?? When I click on the link, "Click Here" It display, "Look At Me!!" but the link, "Click Here" is GONE Is there a way to keep my link, "Click Here" from disappearing? So when I click on the link, "Click Here" the content, "Look At Me!!"should display as well. thanks Here are my codes Code: <html> <head> <script type="text/javascript"> function display() { document.writeln("Look At Me!!"); } </script> </head> <body> <a href="google.com" onClick="display()">Click Here</a> </body> </html> Please, I need a code that is capable of preventing SEOQuake from loading on my websites, even if a user has installed the plug-in. For example, Google, Yahoo and Bing implements such feature. I just don't want it to load whenever anybody visits my sites. I have a set of text boxes sharing the same name that I want to validate onSubmit. If a duplicate is found, I want to alert the user and prevent the form from submitting. How would I check the text boxes for duplicates? Code: <script type="text/javascript"> function Validate() { var obj = document.getElementsByName('keyword'); var i = 0; var rows = obj.length; for (i=0; i<rows; i++) { if (obj[i].value == any of the other text boxes { alert('A duplicate was found.'); return false; } } </script> <form method="post" action="" onSubmit="return Validate();"> <input id="k1" name="keyword" /><br /> <input id="k2" name="keyword" /><br /> <input id="k3" name="keyword" /><br /> <input id="k4" name="keyword" /><br /> <input id="k5" name="keyword" /><br /> <input type="Submit" value="Submit" /> </form> I was curious if there is a method to keep a single input from submitting a form. I have an input into which I'm building a drop down search feature, however, I'd like it so when the user presses return there, instead of submitting the form, it runs an AJAX POST instead. I am currently using keyUp to recognize the button press, but its still submitting the form its attached to. Obviously, I'd like that not to happen. Hello. I have what I think is a simple request, but I'm not quite sure how to go about it. I hope you can help me! Problem: I am building an online store and need to restrict checkout unless a customer has bought at least $20 worth of items. If they have >$20, they can check out. If they have <$20, they should get an error when they click the checkout button that explains that there is a $20 minimum. I don't want them to be able to checkout, so maybe I also need to disable the button or hide it? Here are the two elements in my HTML: The total price div: Code: <div id="totalprice">{tag_productgrandtotal}</div> The checkout button: Code: {tag_buybutton,<img alt="" src="/CatalystImages/shop_checkout.png" />} Here is what I've tried to put together with my bare minimum knowledge of Javascript: Code: <body onload="checkOut()"> <script type="text/javascript"> function checkOut() { var tp = document.getElementById('totalprice').innerHTML; tp = tp.replace(/[^0-9$\.]/g,""); // strip anything except numbers decimals and $ sign if (tp < "$20.00") { ???????????????? } else { ????????????????? } } </script> I'm not sure the top part is correct, and where I've put "?????" I have no idea what to do to deactivate the checkout button and produce the error message. Thank you SO much for any help you can provide. Hi all, I am facing problem in preventing my web page being loaded into an iFrame. I search in internet and found this solution : if (self == top) document.documentElement.style.display = 'block'; else top.location = self.location; The above java script code is simple redirecting me to the home page of my web site. But I donot want that kind of solution. When anybody tried to access my web page through iFrame, it should show an error message like "The content of the web site cannot be loaded into an IFrame". This message should be displayed inside the iFrame. For example, if we tried to access "google.com" site in an iframe, the website should not allow the iframe object to load into it, insted it will display an error message along with a provision to open webiste with an external link with it. Any help? thanks, -Sanath |