JavaScript - Input From A Form Gets Included In Text On Website?
Hi all,
I have this idea - and there might be something already out there that can do it for me - but I don't even really know how to phrase what I'm looking for. Basically, I want the user to be able to enter a word in a text box. When the form is submitted, that word is included in the text in the resulting page in several places. Maybe this example will work well: The text on the website might be this: Quote: Yesterday for lunch I ate a delicious _________. It was the first time in a while I had eaten a _________ and it was even better than I expected it would be. In fact, it was so good that I immediately ran to the store and purchased a whole box of ________s. A user would come to the site and be prompted for a type of food. If they entered banana in the text box and submitted the form, the resulting page would then read: Quote: Yesterday for lunch I ate a delicious banana. It was the first time in a while I had eaten a banana and it was even better than I expected it would be. In fact, it was so good that I immediately ran to the store and purchased a whole box of bananas. Is this even possible? And if so, how difficult would it be to do? Thanks a bunch for the help! Similar TutorialsI 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. Hello all I'm working on a simple feedback form (well not so simple for me) for the last page of my site. In the text area I expect to get normal western text PLUS (or even just) Chinese xharacters my question is how do you validate Chinese character input? low tech Hey everyone. Been racking my brain all day trying to figure out how to duplicate this code with the limited javascript knowledge I have been trying to learn. This code is a Dropdown menu of Yes or No, than a Select button that Opens up a Text Input directly below the dropdown. So far, It works great. My problem is I need at least two of these on the same page and I do not know how to go about it. I have tried changing values to accommodate adding another on the same form, but than both stop working. Can someone Please HELP! Thank you in advance. Code: <html> <head> <SCRIPT language="javascript"> function add(type) { //Create an input type dynamically. var element = document.createElement("input"); //Assign different attributes to the element. element.setAttribute("type", type); element.setAttribute("value", type); element.setAttribute("name", type); element.setAttribute("id", type); var foo = document.getElementById("fooBar"); //Append the element in page (in span). foo.appendChild(element); } </SCRIPT> </head> <body> <label> <SELECT name="element"> <OPTION value="text" name="refer_yes" id="refer_yes">Yes</OPTION> <OPTION value="text" name="refer_no" id="refer_no">No</OPTION> </SELECT> <INPUT type="button" value="Select" onclick="add(document.forms[0].element.value='')"/> </label> <span id="fooBar"> </span> </body> <html> well title says it all i have a search form, and the default value is "enter text here" when the user click the submit button, i would like to check if the value of my text input is "enter text here" and if it is, then don't submit the form (popup a warning or something) how can i do that? thanks a lot! Hi all can someone guide me (total JS newbie) on this presumably pretty easy task? I have a "parent" page with some text inputs in it (a form). This is what I am after: -when the user clicks a link it pops open a new window via JS - "child" (this is working). -in the "child" window there are also some text inputs (another form) (done). -when the user changes the value for 'testChild_textInput_4' in the child window, then I want it to automatically set this same value, to effectively overwrite, what is currently in 'testParent_textInput_2' in the parent window. Presumably this involves an onChange event, but it is also OK with me if the needful (the text input's value in the parent window being overwritten) happens upon the child window's form submit. If anyone can show me either trick, I would be thrilled! I set up a test page to make this all easy to talk about: http://www.yellow-turtle.com/testDumpMe_parent.html Please let me know! Thanks! -John Hey guys, First shot at JS so please be gentle! I'm trying to get this script to clear the default value of my input elements on focus. It works well the first time, however, if a user inputs some fresh text, selects something else, then selects the same input element again, it will clear the text they entered. Make sense? Here's the script (thanks in advance!!): Code: <script language="JavaScript"> function clickFocus(input){ input.className = 'focus'; if (input.value = input.defaultValue){ input.value = ''; } } function unFocus(input){ input.className = 'entered'; if (input.value == ''){ input.value = input.defaultValue; input.className = 'normal' } } </script> <form action="confirmation.php" method="post" enctype="multipart/form-data" name="form" id="form" onsubmit="return checkForm(this)"> <input type="text" name="name" value="Name" onfocus="clickFocus(this)" onblur="unFocus(this)" /> <input type="text" name="email" value="Email" onfocus="clickFocus(this)" onblur="unFocus(this)" /> <input type="text" name="subject" value="Subject" onfocus="clickFocus(this)" onblur="unFocus(this)" /> <textarea type="text" name="message" onfocus="clickFocus(this)" onblur="unFocus(this)" rows="5">Message</textarea> <input class="submit" name="submit"type="submit" value="Send Message" /> </form> like for example i have text areas named upload1 and upload2 when I click or add input on upload1 a drop down list below upload2 will not change, but when I add input on upload2 the dropdown will select "parts" Hello all, My website has a search field at the index page. I want to test this search field for vulnerabilities by entering Javascript. When i enter <script>alert("test");</script> in the search field there comes a pop-up which says: "best" instead of "test". When I enter <script>alert("test123");</script> the pop-up says: "test" instead of "test123" The page source displays the following after I enter <script>alert("test");</script> in the search field. As you can see it changes my "test" input to "best" for some kind of reason. <a href="/searchresults.jsp?searchpage=1&freetext=%3Cscript%3Ealert%28%22best%22%29%3B%3C%2Fscript%3E& pagepart=objectname;description;shorturl&expressionset=&nodelocation=0000000000010000&ds mshowinsearch=true&dateformat=dd-MM-yyyy&creationdatestart=&creationdateend=&modificationdatestart=&modificationdateend= &publicationdatestart=&publicationdateend=&searchbase=0&searchrange=10&expans ion =" class="blauw bold italic"><script>alert(" best ");</script></a> <a href="/searchresults.jsp?searchpage=2&freetext=%3Cscript%3Evoert%28%22test%22%29%3B%3C%2Fscript%3E& pagepart=objectname;description;shorturl&expressionset=&nodelocation=0000000000010000&ds mshowinsearch=true&dateformat=dd-MM-yyyy&creationdatestart=&creationdateend=&modificationdatestart=&modificationdateend= &publicationdatestart=&publicationdateend=&searchbase=0&searchrange=10&expans ion =" class="blauw bold italic"><script>voert(" test ");</script></a> <a href="/searchresults.jsp?searchpage=3&freetext=%3Cscriptie%3Ealert%28%22test%22%29%3B%3C%2Fscriptie%3E& amp;pagepart=objectname;description;shorturl&expressionset=&nodelocation=0000000000010000&am p;dsmshowinsearch=true&dateformat=dd-MM-yyyy&creationdatestart=&creationdateend=&modificationdatestart=&modificationdateend= &publicationdatestart=&publicationdateend=&searchbase=0&searchrange=10&expans ion =" class="blauw bold italic"><scriptie>alert(" test ");</scriptie></a> </p> <p class="sorteer-aantal">Deze zoekvraag levert geen resultaten op</p> So in some way my website changes my input, but what is happening? and is it possible that somebody can abuse this searchfield? Thanks in advance for your reply, Hanna (a newbie with Javascript) Ok, so if you navigate ovr to my website "http://www.mancunianmacca.co.cc" you will notice that a box pops up asking for your name. When you type it in it adds it to the page. Is there a way I can get this to remember the users input and only ask them once then remember. Like cookie or anything. If you need any extra things. Just ask.
Does anyone know if it is possible to use Javascript and HTML to access video+sound input so a user can use a webcam on a site without the need for flash/plug ins? Trying to figure this one out but not finding any good starting points yet. Not even sure if it is feasible. 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 Currently I have several forms using the input text "field3". I want to know how I can require an HTML input text field to be required WITHOUT having to use the form name in the javascript and without modifying <body>,<form> or <input type="submit">. Also no HTML5 since not all browsers use it (life would be simple if they did since threres a required tag) So here is my form, for example Code: <form name = "test"> <input type="text" name="field1"> <input type="text" name="field2"> <input type="text" name="field3"> <input type="submit"> </form> In otherwords, I can only edit <input type="text" name="field3"> by putting code directly before, in, or after that input field. With this problem, how can I make it required? thank you hi folks, i needed a text input so the user that will register a product, will make sure to enter the cents, and not just the raw money, making it to be stored incorrectly on my database. for example, if i type "1" the output inside the text field will be automatically "0.01", so the user HAS to type the cents. thanks in advance hi friends , i am on make a dynamic input field creation code , my problem is the entered text(value from "add proposition") is washing away , if i press new "add proposition" my java script is PHP Code: <script language="javascript" type="text/javascript"> function add() { k=document.getElementById("num").innerHTML k=parseInt(k); if(!k) {document.getElementById("num").innerHTML=1; k=1;} else{ document.getElementById("num").innerHTML=k+1; k++; } document.getElementById("cat").innerHTML+="<br />type propositon "+(k)+":<input type=\"text\" name=\"prop"+k+"\">is it answer? <input type=\"checkbox\" name=\"ans"+k+"\"> ignore this one:<input type=\"checkbox\" name=\"ign"+k+"\">" } </script> my html code is PHP Code: <form action="new.php" method="post"> <fieldset> <legend>Add Question & answer:</legend> question type:<br /> True or False:<input type="radio" name="radio" value="t"> Objective:<input type="radio" name="radio" value="o"> Other:<input type="radio" name="radio" value="o"> Quesion:<br /> <textarea name="desc" rows="6" cols="35" ></textarea> <br /> <a href="javascript:add()" ><b>add proposition</b></a> <div id="cat"></div> <div id="num" style="display:none;"></div> <br> <input type="submit" name="submit"> </fieldset> </form> how i solve this problem ? Hi, I have a form with text boxes which I need to display values ie. <input type="text" name="image_ref" value="image1" /> This works no porblem until I enter the below javscript onto the page: <script type="text/javascript"> var level1 = document.getElementById('level1'); level1.style.display = 'none'; var level2 = document.getElementById('level2'); level2.style.display = 'none'; var all_levels = document.getElementById('all_levels'); all_levels.style.display = 'none'; </script> This code is to hide certain parts of the form until they are activated. the problem is when the parts of the form are activated and displayed, the values inthe text input boxes do not show. Any ideas why this is? many thanks in advance. hi i wants to change one input to texarea when i select one from radio, plz any suggestion how i would do that? my code PHP Code: <input type="text" name="other" value="this need to become textarea" /> <input type="radio" name="inputtext" />Text <input type="radio" name="inputtext" />Textarea so when i click inputtext radio name"other" will become a textrea rather then input type text. thanks for any help. Hi, I'm currently programming a menu editing script and I'm trying to reorder value of text input on change. What I'm trying to do is when I change the value of a text box it reorders the others. EX Start 1 2 3 4 5 Change 3->1 End 2 3 1 4 5 Here is what I've manage to do, it works only when the number is bigger. Javascript function Code: function changeOrder(current) { var num_name = current.name.split("_",2); var id = num_name[0]+"_"+num_name[1]+"_number"; var maxorder = document.getElementById(id).value; var currentmax = current.name.substr((current.name.length-1),1) if(currentmax <= maxorder && current.value > 0) { var start = (currentmax > current.value ? 1 : currentmax); for(var i=start;i<maxorder;i++) { var k = parseInt(i)+1; x = document.getElementsByName(num_name[0]+"_"+num_name[1]+"_order_"+k); x[0].value = i; x[0].name = x[0].name.substr(0,(x[0].name.length-1))+i; } current.name = current.name.substr(0,(current.name.length-1))+current.value; } } HTML input Code: <input type="text" style="width: 20px;" onchange="changeOrder(this);" value="1" name="other_title_order_1"> Thanks for any advices you may have Maxetime I need a javascript that could record the ID/name of a textbox when the user hit delete or backspace to be used on the next page after submission in a PHP script. There are 96 text boxes, they are all randomly placed on the screen with a question that came from a randomized array's keys (the script later checks the values of the textboxes with the values from the array's keys that correlate to the textboxes by the name/id of the textbox, which is assigned by a for loop that issues the next($array) to assign everything everywhere. At the same time, it needs to count how many times the backspace/delete were pushed and have that recorded and sent as well. After 45 minutes of research I've been able to solve the "count the backspace/delete key" problem: Code: <script type="text/javascript"> var count = 0; document.onkeypress=function(e){ var e=window.event || e if (e.keyCode == 8) { //8 is backspace count++; document.getElementById('backspace').value=count; //this is a hidden input } if (e.keyCode == 46) { //46 is delete count++ document.getElementById('backspace').value=count; //the hidden input } } </script> But onto the name/id issue: I'm not sure how to go about retrieving the names/id of the textboxes. I would assume a onkeypress event for every textbox, but hope that there could be something I could just add to this code. Thank you for your help. Hello everybody I have a page where I have several input text fields (the number of fields is variable), the input text fields are disable , only the first one is enable, as the user goes filling out the text fields, the next text field becomes available, each time the user fills out an input text field, the form is submitted. As I said, the number of text fields is variable, some times I have only one and other time I can have 7. I would like to create a javaScript function to put the next available text field ready to star writing, without having to click in the text field first. The id of my form is "reports" , the id of the table is,"run_params" and the id of my input texts is "inputp". I am using JSF, the HTML output generated for each field is id="reports:run_params:1:input" , the number 1 indicated that is the first input text, this number can go from 1 to 20. I have tried to create a code where I can read how many input fields I have and then create a loop that checks all of them and search for the field that is enable and empty, and put that field on focus. But so far my code doesn't work. I don't have too much experience with javaScript and I already have tried many different ideas, without success, I have not idea how to achieve this objective, because I don't know very well javascript's capabilities, so I don't know what it is possible and what it is not. Any help????!!! Thanks in advance Sorry, not sure if I need Javascript for this so I posted it in the html forum as well I'm looking to create a simple page where a user can copy and paste a list of ingredients and then push a button to search that list for a number of key words. Key words: Amodimethicone, Trimethylsilylamodimethicone, Glycerin, Trideceth-12, Behenoxy, Bisamino, Aminoethyl, PG-Propyl, Phenylpropyl, Methicone, Cyclomethicone, Cyclopentasiloxane, Cyclohexasiloxane, Cyclopentasiloxane, Dimethiconol, Trimethylsiloxysilicate, Silicate, Siloxy, Trimethylolpropane, Diisostearoyl, Copolyol, Dodecylbenzenesulphonate, Diphenyl, silicone, Methicone, Simethicone, Trisiloxane, sulfate, Myreth, Lauryl, Laureth, Sulfonate, dodecylbenzenesulfonate, Xylenesulfonate, Ammonium, Isethionate, Sulfoacetate, Sarcosinate, Sulfosuccinate, Carboxylate, Taurate, glycinate I don't care how they are alerted if any of the key words match their ingredients pop up, highlight, whatever. *Incase anyone is wondering it is to search hair products for any form of silcones or sulfates since many people wish to avoid them but they come in many different forms. Thanks!! |