JavaScript - Multiline Textbox Validation Behaves Differently In Ie And Ff
hi all , i want that user can not enter text in multiline textbox more than specific characters but it behaves differently in IE and FF. In Internet explorer when i press enter key it takes two character whereas in firefox when i press enter it takes only one character. so this way user can enter more data in FF which is not correct. how to fix that behavior so that both browsers give same result. My javascript code is given below
<HTML> <HEAD> <TITLE> Javascript Character Count by WebSewak.com </TITLE> <script language="Javascript"> function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) { var countedTextBox = opt_countedTextBox ? opt_countedTextBox : "counttxt"; var countBody = opt_countBody ? opt_countBody : "countBody"; var maxSize = opt_maxSize ? opt_maxSize : 1024; var field = document.getElementById(countedTextBox); if (field && field.value.length >= maxSize) { field.value = field.value.substring(0, maxSize); } var txtField = document.getElementById(countBody); if (txtField) { txtField.innerHTML = field.value.length; } } </script> </HEAD> <BODY> <textarea id="counttxt" name="counttxt" rows="10" onkeyup="counterUpdate('counttxt', 'countBody','30');"></textarea> You typed <B><span id="countBody">0</span></b> characters Max. Length : 30 Chars </BODY> </HTML> Similar TutorialsHi, I am having a very difficult time trying to get my text box to validate. I successfully validated my first program using prompts but now when I am using a HTML form I cannot get it to work. I have spent hours upon hours trying to get this working, any help would be greatly appreciated. Code: <html> <head> <title></title> <script type="text/javascript"> function validateform() { var temp = document.forms["inputform"]["temperature"].value while ((isNaN(temp)) || (temp == "")) { alert("Please enter a number"); return false; } if (parseFloat(temp) > 35) { alert("Wow, it's really hot!"); } else if (parseFloat(temp) <= 35) && (parseFloat(temp) >= 18)) { alert("It's a comfortable temperature right now"); } else if (parseFloat(temp) < 18) { alert("Brrr, it's a little bit cold for my liking"); } else { alert("Goodbye, and thanks for using TempReader"); } } </script> </head> <body> <form name="inputform" method="post" action=""> <table> <tr><td>What Is The Temperature?</td><td><input type="text" name="temperature"></td></tr> <!-- Below is submit button that when pressed validates the form --> <tr><td></td><td><input type="submit" value="Submit Details" onclick = validateform()></td></tr> </table> </form> </body> </html> My code is not validating the textboxes..if someone could help me figure this out. Thank you <script type="text/javascript"> function validate() { with (document.form1) { var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; var alertMessage = "The following fields\nare REQUIRED:\n\n"; if (realname.value == "") { alertMessage += "Name\n" } if(reg.test(email.value) == "") { alertMessage += "Email\n" } if (phone.value == "") { alertMessage += "Phone\n" } if (security_code.value == "") { alertMessage += "Security Code\n" } if (alertMessage != "The following fields\nare REQUIRED:\n\n") { alert(alertMessage); return (false);} return (true) } } </script> <form action="formmail.php" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return validate()" > Reply With Quote 01-31-2015, 09:12 AM #2 Philip M View Profile View Forum Posts Supreme Master coder! Join Date Jun 2002 Location London, England Posts 18,371 Thanks 204 Thanked 2,573 Times in 2,551 Posts Have you tried using your error console (F12 key)? if(reg.test(email.value) == "") { should be if(!reg.test(email.value) { as test returns true or false. But form validation of the pattern if (document.formname.formfield.value == "") - that is blank or empty- is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. A proper name may only contain letters, hyphen, space and apostrophe. Numeric values, such as zip codes, phone numbers and dates, should be validated as such. Ditto email addresses (as you have done). This topic has been covered many times before in this forum. The use of with is strongly deprecated and is forbidden in strict mode, and alerts are long obsolete as a way of displaying a message to your users. And so is assigning a name to a form - it is allowed only for the sake of backwards compatibility. In short - you should rewrite your code to modern standards. Hi, I have a text-box where you enter the phone nos. On key-press, i have written a validation code to enter only nos and "-". I have disabled Ctrl+v, but my customer want to enable ctrl+v for that text-box only. My requirement is after pasting the value it should automatically check for validation.. How to do it? Thanks... HI, I am not a programmer. however, i am working with a website wherein on its registration page there is this text box to enter the name. No for example if I have to enter my name as John Smith it does not allow as it is validated in a way that it does not allow the space. Now my web development agency is charging a bomb to revalidate just that one text box. can someone help me with the coding or steps involved to validate this text box. And howmuch time will it take. I have a simple html form with 2 text fields and submit button 1 user name 2 pwd/token and 1 checkbox 'First time user' if 'first time user' is selected then the 'Submit' button to be enabled only if the customer puts exactly 6 digits on pwd/token. if it's unchecked then the submit button to be enabled only if the customer enters 10 digits(pin_token code) please send me code will be very thankful for your help Okay I have searched google for hours literally without luck so hopefully someone here can help. What I am trying to do is when someone submits the form if there are empty textboxes change the textbox's style from class="input" to class="inputreq". Someone please help, the formname is "signup" and the textboxes are "domain" and "username". Please help. Thanks. Hi there, I have this form that validates a few textboxes & a dropdownlist. And when it is not filled in, the border of the textboxes and dropdownlist would turn red, followed by an alert message notifying which field have not been filled in. Else, the border will revert back to black, and the form will be submitted successfully. Right now, I would like to prevent the user from entering blanks (like entering a space to cheat the system). How should I tweak the codes to make it work? Javascript Code: function check(checkForm) { var fields = new Array("Name","Email Address", "Domain Name"); var index = new Array(),k=0; for(var i=0;i<fields.length;i++) { var isFilled = false; var c = document.getElementsByName(fields[i]); for(var j = 0; j < c.length; j++) if(!c[j].value == "") { isFilled = true; c[j].className = "defaultColor"; } else { c[j].className ="changeToRed"; } if(!isFilled) { index[k++] = fields[i]; } } if(k>0) { joinComma = index.join(', '); alert('The field(s) corresponding to '+ joinComma + ' is/are not selected.'); return false; } } HTML Code: * Name: <input type="text" id="Text27" name="Name" /><br /> <br /> *Email Address: <input type="text" id="Text28" name="Email Address" /> @ <select id="Select5" name="Domain Name"> <option></option> <option>hotmail.com</option> <option>yahoo.com</option> </select> <input id="Submit5" type="submit" value="Submit" onclick="return check(checkForm)"/> I am using ASP validators and I have a contact form. I want to be able to have a phone and email radio button group. The email textbox also has a RegularExpressionValidator If the phone item is selected then I want the validation to be enabled on the phone text box making it mandatory while the email text box isn't, and if they choose the email as the contact it will be reversed. I want to be able to do this without having to do a postback. I already have the logic on the code behind and the enquiry object. also I am fairly new to javascript so I have been using mostly jQuery as easier to implement Hi! I am trying to use innerHTML but unsuccessfully on my Wordpress website. Please see the following code: Code: var string = "<?php the_content(); ?>"; function textchange() { document.getElementById('box_content_slideshow').innerHTML = '<div class="box_content">'+string+'</div>'; } The problem is that when wordpress puts the content in the variable 'string', it automatically adds carriage returns/line break result in: Code: var string = "<p>heading</p> <p>sample text</p> <p>more text</p>"; Is there any way I can remove the line breaks making the string like: Code: var string = "<p>heading</p><p>sample text</p><p>more text</p>"; I have tried using: Code: var string = (<r><![CDATA[ The text string goes here. Since this is a XML CDATA section, stuff like <> work fine too, even if definitely invalid XML. ]]></r>).toString(); But this only works in FF, and not in IE, Opera, or Safari. Thanks a lot! Cheers! Hello i Have this Marquee Code , I use it in My smarty Template , All working fine ,with IE8 , but with Firfox , it dose Not .. Firefox will Not Show the Buttons for speed up , slow down , right , left ..under the table but instaed will include it with the Marquee.. the Strang thing if i open the Template direct to Firfox , the buttons shows up but No effect , means when u click any button will not change the Directions.. PHP Code: <marquee id="last_feed" behavior="scroll" direction="up" scrolldelay="10" height="100px" scrollamount="2" onmouseover="this.setAttribute('scrollamount', 0, 0);" onmouseout="this.setAttribute('scrollamount', 2, 0);" > <{foreach item=project from=$myproject}> <p dir="rtl"> <div> [ <{$name}> : <b><{$comment}></b> :: <{date}> ] <img border="0" src="images/logo2.gif" width="18" height="18"> <{/foreach}> </p> </div></marquee> <div> <img src="images/Right-arrow-32.png" title="To Right" border="0" align="center" style="cursor:hand;" onclick="document.all.last_feed.direction='right';document.all.last_feed.start();" width="16" height="16"> <img src="images/Left-arrow-32.png" title="To Left" border="0" align="center" style="cursor:hand;" onclick="document.all.last_feed.direction='left';document.all.last_feed.start();" width="16" height="16"> <img src="images/Up-arrow-32.png" title="UP" border="0" align="center" style="cursor:hand;" onclick="document.all.last_feed.direction='up';document.all.last_feed.start();" width="16" height="16"> <img src="images/Down-arrow-32.png" title="DOWN" border="0" align="center" style="cursor:hand;" onclick="document.all.last_feed.direction='down';document.all.last_feed.start();" width="16" height="16"> <img src="images/plus.gif" title="Speed Up" border="0" align="center" style="cursor:hand;" onclick="document.all.last_feed.scrollAmount=5;" width="12" height="12"> <img src="images/minus.gif" title="Slow Down" border="0" align="center" style="cursor:hand;" onclick="document.all.last_feed.scrollAmount=3;" width="12" height="12"> </div> Hi.. I have form and i want to input data using barcode and it will display on textbox and after input on the first textbox the focus will go to next textbox untill it will go on the last textbox and on the last textbox it will automatically save the data's on the database. How is it possible? here is my sample code: Code: <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); ?> <html> <head> <script type="text/javascript"> function ini() { // Retrieve the code var code =document.getElementById ("code_read_box1").value; var code =document.getElementById ("code_read_box2").value; var code =document.getElementById ("code_read_box3").value; var code =document.getElementById ("code_read_box4").value; var code =document.getElementById ("code_read_box5").value; var code =document.getElementById ("code_read_box6").value; // Return false to prevent the form to submit return false; } </script> </head> <body onLoad="document.barcode.code_read_box1.focus()"> <form name=barcode onsubmit = "return ini()"> <input type="text" id="code_read_box1" value="" /><br/> <input type="text" id="code_read_box2" value="" /><br/> <input type="text" id="code_read_box3" value="" /><br/> <input type="text" id="code_read_box4" value="" /><br/> <input type="text" id="code_read_box5" value="" /><br/> <input type="text" id="code_read_box6" value="" /><br/> </form> </body> </html> Hello. I've been teaching myself HTML and CSS for a while, and now I've moved into the world of Javascript (but I'm still very much a beginner). For practice, I've been building a sample sign up form for a mock website, and I'm having problems with the birthdate section. The idea I had was to have MM, DD, and YYYY be the default values of my 3 textboxes (as an example for users), then set the value to nothing when the box gained focus. That all works fine, but I ran into problems when I tried to write an if statement to set the value back to MM, DD, or YYYY if the value was still nothing when the user clicked away. As it is now it just replaces the text inputted into the textbox (which of course is not good). Any ideas for what the problem might be? Code: <form name="signup" action="javascript:void(0);" method="post"> <table> <tr> <td>Date Of Birth:</td> <td> <input name="DOBmonth" type="text" value="MM" size="2" style="color: #555555;" onFocus="clearDOBmonth()" onBlur="restoreDOBmonth()" /> <input name="DOBday" type="text" value="DD" size="2" style="color: #555555;" onFocus="clearDOBday()" /> <input name="DOByear" type="text" value="YYYY" size="4" style="color: #555555;" onFocus="clearDOByear()" /></td> </tr> <tr> <td></td> <td><button name="Submit" type="submit" style="font-size: 1em;">Sign Up</button></td> </tr> </table> </form> <script type="text/javascript" language="javascript"> <!-- document.signup.DOBmonth.value="MM"; document.signup.DOBday.value="DD"; document.signup.DOByear.value="YYYY"; function clearDOBmonth() { document.signup.DOBmonth.value="";} function clearDOBday() { document.signup.DOBday.value="";} function clearDOByear() { document.signup.DOByear.value="";} function restoreDOBmonth() { if ('document.signup.DOBmonth.value = ""') { document.signup.DOBmonth.value = "MM"; // alert(document.signup.DOBmonth.value); } } //--> </script> Another side question, if I set a variable equal to the value of a textbox, then change the value of the variable, does that also change the value of the textbox? or is the variable no longer associated with the textbox. Example: Code: var a = document.form.textbox.value; a = blue; does document.form.textbox.value = blue? or is var a now completely independent of the textbox value? Thanks! Does anyone know why Chrome's alert responses are different to IE and FF? Code: <script> function checkDriveletter(){ var drive=0; var drive = readCookie('choose'); alert(drive); createCookie('choose',1,9999); var drive = readCookie('choose'); alert(drive); } window.onload=checkDriveletter; </script> In Chrome the cookie never seems to get set. My cookie code is: Code: function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function eraseCookie(name) { createCookie(name,"",-1); } I am creating web page. I am in the early stages of building. But I have found that my onChange function behaves different on Firefox and IE. It work as it suppose to on Firefox but not on IE. On IE, onChange is not triggered when you select the an option. But triggers when you click the mouse the second time. Here the code, Code: <html> <head> <title>Compatibility Test</title> <script type="text/javascript"> var myScore = 0.1; function correct(val) { alert(val.value); } </script> </head> <body> <center> <font size=7>Welcome to Compatibility Test</font><BR> <I>by<BR>Rohn DeSilva<BR></I> </center> <BR><BR><BR> 1. Who is the father of relativity?<BR> <input type="radio" name="q1" value=2 onchange="correct(this)"> <B>Isaac Newton</B> <input type="radio" name="q1" value=3 onchange="correct(this)"> <B>Albert Einstein</B> <input type="radio" name="q1" value=1 onchange="correct(this)"> <B>Marie Currie</B> <BR><BR> </body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en" > <title>Assignment 5 - JavaScript Loops</title> <head> <script type="text/javascript"> function getGrade(){ var i= Number(document.getElementById("input1").value); m=Math.floor(i/2); for(var k=1; k<=i; k++){ for(var j=1; j<=k; j++){ document.write(j+" "); if(j==k){ document.write("\n"); } if(j==i){ decreaseLoop(j, k); } } } function decreaseLoop(j, k){ for(k=k-1; k>0; k--){ for(var l=1; l<=k; l++){ document.write(l+" "); if(l==k){ document.write("\n"); } } } } } </script> <style type="text/css"> #main{ margin:auto; width:70%; } #top{ font-size:20px; font-weight:bolder; color:#007700; text-decoration:underline; } #s1{ font-size:20px; font-weight:bold; color:#7700ff; } #s2{ font-size:20px; font-weight:bold; color:#00ff00; } #s3{ font-size:20px; font-weight:bold; color:#ff0000; } #form1{ width:600px; height:80px; padding:20px; background-color:#aaaaaa; } </style> </head> <body> <div id="main"> <p id="top">Assignment 5 - JavaScript Loops</p> <span id=s1>This is Form for checking Loop</span> <form id=form1 name=form1> <table> <tr><td>Enter Number </td><td>: <input type="text" id=input1 name="input1" /></td></tr> <tr><td><input type="button" name=btn1 value="Get Number" onclick=getGrade() /></td></tr> </table> </form> </div> </body> </html> When I execute this code, on the screen I see all output in one line. Which is not hat I want. But when I see it in Firebug (for firefox)or Developer Tool Bar(for IE) , I see it printed out in pyramid form(as required). So why is this output in one line on screen ? How cn I get it in pyramid form ? Thanks Hey all. I have a simple validation I need to do. I need to just make sure that a Checkbox is checked, and that a Text field has content. Sounds simple but I cannot find any thing that has a check and a text field. Here what I have. Can I modify this script to do this? A Checkbox MUST be checked and Text field MUST be filled out. This currently does the text field fine, but no Checkbox obviously. How can I add a checkbox validation to this? Thats it. Any help is appreciated. Code: <script type="text/javascript"> var textFields = ["digsig"]; function validateForm( ) { var oops = ""; // must initialize this! var form = document.sig; for ( var t = 0; t < textFields.length; ++t ) { var field = form[textFields[t]]; var value = field.value.replace(/^\s+/,"").replace(/\s+$/,""); // trim the input if ( value.length < 1 ) { oops += "You MUST enter your Digital Signature"; } } if ( oops != "" ) { alert("ERROR:" + oops); return false; } } } </script> Hello all, new here Seems like a very nice place to be apart of. I have my website www.gebcn.com. If you view source you will see all that I have done, but more importantly my problem. I have the JS code at the top there and I am unable to W3C validate my HTML because of the JS. I am using XHTML strict and would like to stay using it. The JS I have at the top is my form validation code. I am able to do any validating that I need with this "snippet" of code, I have shrank it from my library version just to use for this newsletter. Until now W3C validating was not important now for some reason it is and I am faced with this problem. I am not a Javascript guy more of a HTML/CSS guy and I can manipulate JS to suit my needs. <problem> I have tried to make this "snippet" of JS code an external file but receive multiple errors with the JS calling for the FORM NAME as it is not on the same page. The form NAME=NEWSLETTER is another problem, as W3C says I am unable to use attribute "NAME" in this location. <problem> I would like to keep the JS close to how it is now as I have a library to use this JS over and over again. Any pointers in the right direction or solutions to my problem would be greatly appreciated. Thanks! Hopefully it is not to hard huh If there is anything anyone needs, the code pasted here, or anything else please let me know. Thanks again! Hi, i got a textbox with a submit button but when submit button is clicked it works but it reloads the page. is possible to submit without reload the page? thanks |