Convert Input Text To Lowercase On Submitting A Form December 22, 2023 Post a Comment I have a form in which there is one text field is provided with a submit button.On clicking submit button,it redirects to second php page from first php page. index.php Solution 1: There was a few errors, you were missing the right angle bracket on </form> and you were trying to write the value rather than setting the field value, try this...<formaction="submit.php"method="get"><inputtype="text"name="search"id="search" /><inputtype="submit"value="submit"onclick="convert();" /></form><scripttype="text/javascript">functionconvert() { alert("hi"); var str; var srch=document.getElementById("search"); str = srch.value; srch.value=str.toLowerCase(); } </script>CopySolution 2: You can do this only using javascript with a few extra stuff:1) Give your <form> an id <form action="submit.php" method="get"id="form1"> Copy2) Make your <input> type as button. The reason for this is because we want to make sure the convert() function is executed first, and after that we will submit the form.<inputtype="button" value="submit" onclick="convert()" /> Copy3) Finally javascript to:functionconvert() { alert("hi"); var str ; str = document.getElementById("search"); str.value = (str.value.toLowerCase()); //get the form id and submit itvar form = document.getElementById("form1"); form.submit(); } CopyFiddleBaca JugaCatch Javascript Customevent By Jquery On() Preserving Custom Properties At First "level"How To Reload Javascript Code BlockJquery .post And Form DataSolution 3: You are use form element so you can get any elements inside form element access by name, Here Our form name is form1 and inside this form inputboxname="search" and access this value by this way, document.form1.search.value.toLowerCase();Check this Demo jsFiddleJavaScriptfunctionconvert() { alert("hi"); var str = document.form1.search.value.toLowerCase(); document.writeln(str); //console.log(str); } CopyHTML<form name="form1" method="get"> <input type="text" name="search"id="search" /> <input type="submit" value="submit" onclick="convert();" /> </form > CopySolution 4: try like this: alert("hi"); document.getElementById("search").value = document.getElementById("search").value.toLowerCase(); returntrue; CopyFiddle Live Share You may like these postsCan't Get Php Variables In The Js Script When Setting Highcharts Head TagPost Formdata To Php Using Javascript And XmlhttprequestDiv Remains Visible After The Page ReloadsExternal Popup Onclick To Open Only Once Per Session Post a Comment for "Convert Input Text To Lowercase On Submitting A Form"
Post a Comment for "Convert Input Text To Lowercase On Submitting A Form"