JavaScript - Limit, Edit, And Restrict Character Input In Form
Hi all.
I have the form below... Code: <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <form action="thankyou.php" method="get"> <td width="16%"><b>Your Name</b></td> <td width="84%"<input type="name" size="50" name="name" id="name"</td> </tr> <tr> <td width="16%"><b>Your E-mail</b></td> <td width="84%"<input type="text" size="50" name="email" id="email"</td> </tr> <tr> <td width="16%"><b>Text Area</b><br>Limit 50,000 characters<br>X amount characters left</td> <td width="84%"><textarea name="summary" id="summary" cols="50" rows="10"></textarea></td> </tr> <tr> <td><b>Video URL</b></td> <td><input type="text" size="50" name="video" id="video"></td> </tr> <tr> <td><b>Upload Image</b></td> <td><input type="file" size="50" name="image" id="image"></td> </tr> <tr> <td><br><input type="submit"></form> </td> <td</td> </tr> </table> I would like to change it so... When somebody submits a Video URL, the Upload Image input box is disabled When somebody does an Upload Image, the Video URL field is disabled If somebody enters more than 1,000 characters in the Text Area, then both Video URL and Upload Image fields are disabled. When somebody enters a Video URL or does an Upload image, the Text Area is limited to 1,000 characters For the words "Limit 50,000 characters" to change to "Limit 1,000 characters" if somebody enters a Video URL or Upload Image Where it says X amount characters left, it should changing depending on the amount of characters a user has typed in. Can anybody please help me achieve this above using JavaScript? It would be infinitely appreciated. Thank you. Similar TutorialsI want to limit a textarea to 500 characters. So somebody can't type in more than 500 characters or paste anything with more then 500 characters in the text box. However, if somebody were to enter something into the fields favoritedrink OR to favortefood, then I want the limit to change to 100 characters for the textarea. How can I do that using Javascript? I am using the form code below as an example. Code: <form action=""> <input type="text" name="firstname"><br /> <input type="text" name="lastname"> <textarea rows="2" cols="20" name="description"></textarea> <input type="text" name="favoritefood"> <input type="text" name="favoritedrink"> </form> I need some help for my site and would so much appreciate if somebody can help me with my problem. Thanks so much for any help. Is there any way that I can have multiple textboxes where the user can enter text (such as "black or green") and it would edit a css file, like this: Code: <style> body{ background-color:INPUT; } </style> <input type="text" name="bg"/> ? Hi, I am not sure if what I am trying to do can be done, but basically I want to add/edit/delete information in a text area from inputs. I know how to add from inputs to text area but I am struggling with the edit and delete. Code: <script language="javascript" type="text/javascript"> function addtext() { var newtext = document.AddProduct.extran.value + ":" + document.AddProduct.extrav.value + "|"; var newfields = document.AddProduct.extran.value + ":" + document.AddProduct.extrav.value + "|"; document.AddProduct.extraf.value += newtext; document.getElementById("fields") += newfields } function removetext() { var re = new regExp("(^|,)\\s?user3","gi"); document.getElementById('extraf').innerHTML = document.getElementById('extraf').innerHTML.replace(re,""); } </script> </head> <body> <form method="post" enctype="multipart/form-data" action="process-forms.php" name="AddProduct" class="admin_form"> <dl> <dt><label for="Addfield">Custom Field(s) :</label></dt> <dd>Name: <input size="10px" type="text" name="extran" id="extran" value=""> Value:<input size="10px" type="text" name="extrav" id="extrav" value=""></dd> </dl> <dl> <dt>blej</dt> <dd><textarea name="extraf"></textarea> <input type="button" value="Add New Text" onClick="addtext(AddProduct);"><br/> <input type="button" value="Remove Text" onClick="removetext();"> </dd> </dl> <div name="fields" id="fields">here</div> </form> Currently if you click add, it adds the 2 input fields in to the text area separated by : and then ended by | so I can determine new lines, the first input will be "name" the second will be the "value". What I would like to do is be able to edit and delete these from the text area if possible? Hope some one can point me in the right direction? Thanks I am thinking this should be fairly easy but yet I am not getting far. I want to have a form with a single text imput field for a zip code. Depending on which zip code the user enters will determine which url they will be sent to. If they enter a zip code which is not in the script, they would be sent to a default url. I am also assuming this can be accomplished with javascript. Any help is greatly appreciated. hi everyone im here again begging for your help im innocent in this field is there a javascript for setting up a limit in form submit attempts by which someone's attempts can be reset for given time? Shall we say you could try again after 10minutes or tommorow or whatsoever. for example in my form: <form blahblahblah...> <input value=""...blahblahblah/> (then here it goes my problem, if the input value above IS NOT EQUAL to "MYUSERNAME" then limit the form submission attempts to 10 tries, else a warning box will appear saying "You have reach the maximum tries per day") <input type="submit" value="Submit"/> </form> thank you so much and may the God Bless you for your kindness! Hi, i want to set an input value to the same value as the input selected from another input on the same form so when the user selects input 1 i want the hidden input2 to get the same value im guessing i use onsubmit because its hidden so there wont be a focus or blur this would be part of the input Code: onsubmit="(this.value = this.othervalue)" othervalue being the other input name="othervalue" is that the correct syntax I'm currently generating some tooltips to display data for certain items in a game. The tooltips and stats work great, however, for certain items, the tooltip gets long and will extend pass the viewable range for the user. Here are the links: test page: http://cory.wellen.googlepages.com/Build_Hover_Test.htm javascript: http://cory.wellen.googlepages.com/hover.js css (for hover div only): http://cory.wellen.googlepages.com/affe.css If you hover over the links of items (like villages, barracks, etc.) a tooltip will pop up to show you the stats. But if you notice, for items like castles, the tooltip can extend past the viewable range for the user. Any suggestions are greatly appreciated. Hey guys, have a bit of an issue/question... Not sure what I am doing wrong...i do not know javascript at all lol I have a URL stucture which needs to be changed according to the input fields https://sls.example.com/Spc/viewUserProfile.do?source=search&UserId=J-DOE123&vgroupName1=Dealer-jcode-USA-P4038P0122&adminflag=Y This part stays the same at all times https://sls.example.com/Spc/viewUserProfile.do?source=search&UserId= after the "=" sign, I want it to input text from a input box "J-JOE123", so if I put J-DOE123 in the first input box and run the search, I want it to pull up https://sls.example.com/Spc/viewUserProfile.do?source=search&UserId= J-DOE123 after the "J-DOE123", the next part "&vgroupName1=Dealer-" remains the same at all times https://sls.example.com/Spc/viewUserProfile.do?source=search&UserId=J-DOE123 &vgroupName1=Dealer- the next input box would have a drop down with 2 selections (jcode and lcode) so depending on which one is chosen, that is how it would populate the URL https://sls.example.com/Spc/viewUserProfile.do?source=search&UserId=J-DOE123&vgroupName1=Dealer- jcode next, i would need for it to put a "-" after the chosen jcode or lcode in the URL, which will also be there at all times https://sls.example.com/Spc/viewUserProfile.do?source=search&UserId=J-DOE123&vgroupName1=Dealer-jcode - the next input box would have a drop down with 2 selections (USA or CAN) so depending on which one is chosen, that is how it would populate the URL https://sls.example.com/Spc/viewUserProfile.do?source=search&UserId=J-DOE123&vgroupName1=Dealer-jcode- USA next, i would need for it to put a "-" after the chosen jcode or lcode in the URL, which will also be there at all times https://sls.example.com/Spc/viewUserProfile.do?source=search&UserId=J-DOE123&vgroupName1=Dealer-jcode-USA - next, i will have a drop down box containing several hundred codes such as "P0122" and many more. for this, I would need for the display value to be "P0122" but when the URL gets populated, it would have to be "P4038P0122" https://sls.example.com/Spc/viewUserProfile.do?source=search&UserId=J-DOE123&vgroupName1=Dealer-jcode-USA- P4038P0122 The reason why the entire code must change is because P0122 would be P4038P0122, but if it is P0165, it would be N1534P0165, so each code would have its own first part and second part, but in the drop down box, i want it to only display the 2nd part P0122/P0165/etc.. because that is what I go by, but the system only reads full codes. I do have a spreadsheet with the entire list of FULL codes and can do an extract from each cell in order to get the SHORT code. and finally, the URL would have to end with "&adminflag=Y" and will remain the same at all times. https://sls.example.com/Spc/viewUserProfile.do?source=search&UserId=J-DOE123&vgroupName1=Dealer-jcode-USA-P4038P0122 &adminflag=Y So, all together I would have 4 input fields in the form. UserID, jcode/lcode, USA/CAN, and Code. Please help who ever can. If you need more info, please let me know and I shall try my best to explain further. Thanks in advance guys Not sure how to describe this. I've been tasked with the responsibility of creating a web form. That's not the problem and I can do that. The trick is, each field needs to be incased in it's own box that flies in from the left. So, the first box that flies in from the left would be email address, when you click enter, it flies off to the right and the next box flies in from the left asking for the persons name. Is it possible to do this and where might I go to learn more about doing this type of coding. Hi, I've devised a javascript to guess what a user is typing in. That all works, but I'm stuck on how to take that value the user has submitted and put it back into the form. At the moment my form is: <form method="post" action="/bin/openathenssp_isapi.dll?type=ukfed&dir=req&requestURL=index.php" onsubmit="send_sso('login_form', 'loading', '<?=SITE_URL?>'); return false;"> <input type='text' name='uni_name' id='uni_name' value='' autocomplete="off"> <input type="hidden" name="entityID" id="entityID" /> //Where the name is guessed <script>actb(document.getElementById("uni_name"),customarray);</script> <input type='submit' name='submit' value='submit'> </form> So basically I'm trying to put uni_name into the entityID. Here's my javascript: function send_sso(ajax_div, loading_div, site_url) { replace_this_div = ajax_div; replace_loading_div = loading_div; var entityID = document.getElementById("entityID").value; if (uni_name == "Bournemouth University"){ document.getElementById('entityID').value = "https://idp.bournemouth.ac.uk/shibboleth"; ...MORE INSTITUTIONS GO HERE... } else { alert("Sorry, the institution '" +uni_name+ "' was not recognised or does not have access to this service."); } } But this does not seem to be working - any ideas? Allright, so i got index html, and on the head of the document i got jquery already, and what i got is a form, and what i want it to do is that once the input is sumbmited, to post it on a list. BUt something is missing here or maybe im doing it wrong, i need some guidance plz. here is my table: Code: <form name="postbar_add_post" id="postbar_add_post" method="post"> <fieldset> <legend>Write text here ...</legend> <input type="text" name="addcontentbox" id="addcontentbox" /> <input type="button" name="addpost" value="Submit" class="submit" /> </fieldset> </form> and heres is the function that i have on the head, where what i try is to make it post on the list: Code: <script type="text/javascript"> $(document).ready(function(){ $("form#postbar_add_post").submit(function() { var message_wall = $('#addcontentbox').attr('value'); $.ajax({ type: "POST", data:"addcontentbox="+ addcontentbox, success: function(){ $("ul#wall").prepend("<li>"+addcontentbox+"</li>"); $("ul#wall li:first").fadeIn(); } }); return false; }); }); </script> But is just not working :S .... any ideas/guidance? xD . Btw, on the body, theres only that table above, and a " <ul id="wall"></ul> " , wich is where im trying the content to be posted on. Any ideas where the flaw is ? =\ Hi, I have a registration form with the following input field: textbox -name textbox -surname textbox -phone listbox - country listbox - state Am populating my country & state listbox from my database, state depends on the country. However when i select my country&state the page refreshes & all my other values i.e name, surname, phone & others disappears i have to retype all again, any suggestion? thanks this is my javascript used to validate form.having problem when one selection is made and submit button is clicked.the checked button becomes unchecked. i've to check all the radio button in order to proceed with submission. here is the code...anyone pls help how to solve this..tq <script type = "text/javascript"> function validate_form ( ) { valid = true; if ( ( document.myform.gender[0].checked == false ) && ( document.myform.gender[1].checked == false ) ) { alert ( "Please choose your Gender: Male or Female" ); gender.focus(); valid = false; } if ( ( document.myform.nationality[0].checked == false ) && ( document.myform.nationality[1].checked == false ) ) { alert ( "Please choose your Nationality" ); nationality.focus(); valid = false; } if ( document.myform.age.selectedIndex == 0 ) { alert ( "Please select your Age." ); age.focus(); valid = false; } return valid; } </script> Using .htaccess i have a password protected folder online containing 7 files with one single user/pass combination. User is not allowed to see that 7 files are available. User enters 1 of 7 "Access Keys" in a simple HTML Form text input which is then processed (script?) User is then redirected automatically to the related file (for download) e.g. Access Key #1 redirects user to Protected File #1 Access Key #4 redirects user to Protected File #4 etc. What's the best way to implement this? Perl/CGI? PHP? Javascript? Hey all, i'm new here and first off, i'd just like to offer my sincerest appologies if i've posted this in the wrong section! I've made some basic HTML web sites in the past and now the company i work for has asked me to make one. Its a rubber roller manufacture company and i would like to make a page that will have input fields and a submit button that will send the inputted details to our sales manager's email address...something like this Contact Name: (input box) Company Name: (input box) Roller Diameter: (input box) Required Compound: (input box) Email Address: (input box) (SEND BUTTON) Also it would be a massive help if someone could tell me if it is possible for me to set it so that once the send button is clicked, it will send an email of the data but also redirect to another page (just saying thanks for input etc etc) HUGE thanks in advance!!! Hi everyone, im new to javascript and I have created two forms.. a value will be put in the first field and the second field should display either $20 or $35 depending on the value of the first field. Im doing something wrong here.. but I cant see what. Any help is appreciated. <!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 content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>Distance from Depot</title> </head> <body> <form id="distanceform"> <ul> <li> <label for="Distance from EverWarm Depot">Distance from Depot (km):</label> <input type="text" id="distance" class="large"/> </li> </ul> </form> <input name="Button1" type="button" value="calculate" onclick="deliverycost()"/> <form id="deliverycostform"> <ul> <li> <label for="Delivery Cost" >Delivery Cost:</label> <input type="text" id="deliverycost" class="large"/> </li> </ul> </form> <script> function deliverycost() { /* Here is the delivery cost: less than or equal to twenty kilometres is $20.00 greater than twenty kilometres is $35.00 */ var distance = document.forms["neworder"]["distance"].value; if(distance<20) { document.getElementById('deliverycost').innerHTML="$20"; } else { document.getElementById('deliverycost').innerHTML="$35"; } } </script> </body> </html> 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. I'm trying to figure out how to add a length paramater to this function. Not quite sure how to do it. here's what I tried: Code: var phone = document.getElementById('phone'); if(isNumericdashes(phone, "Please enter a valid phone number")){ return true; } function isNumericdashes(elem, helperMsg){ var numericExpression = /^[0-9\(\)-]+$/; if(elem.value.match(numericExpression) &&(elem.length > 9)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } Hi guys, I am new to Javascript and I'm trying to set up a form to make simple calculation based on user inputs. I have set up the form and am unable to get the calculation to work despite what I try (this is based on an online tutorial I found though). Is there any where I am going wrong? Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <script type="text/javascript" language="javascript"> function kanban() { //variables A = document.frmone.annualdemand.value; B = document.frmone.demandVariability.value; C = document.frmone.weeksHold.value; D = document.frmone.ContainerSize.value; E = document.frmone.totalStock.value; //calculation F = A/240; double G = (b/100)+1; H = g*F; c = c*5; i = c*H; j = i/d; document.frmone.totalStock.value = i; document.frmone.noKanBans.value = j; } </script> <title>Insert Title Here</title> </head> <body> <form name="kanban" id="frmone"> Annual Demand: <input type="text" name="annualDemand" value=""/> </br> Demand Variation: <input type="text" name="demandVariability" value=""/> </br> Stock to Hold (weeks): <input type="text" name="weeksHold" value=""/> </br> Size of Container: <input type="text" name="containerSize" value=""/> </br> </br> <input type="button" name="calculate" value="Calculate" onclick="kanban()"/> </br> </br> Total Stock: <input type="text" name="totalStock" value=""/> </br> Qty of Kan Bans: <input type="text" name="noKanBans" value=""/> </br> </form> </body> </html> Thanks guys. Is it necessary (or advisable) to place <form> tags around input buttons? They seem to work fine either way. Code: <input type="button" value=" Home " onClick="parent.main.location='home.htm'"> |