IreneLing Posted September 28, 2011 Share Posted September 28, 2011 Hello all . I'm going to create a function that will auto create a textbox when I typed certain word in my textarea , let's say , when I type "First Name" in a textarea , then it will automatically(without press any button) create a new text box below the textarea and allow me to enter a value , then when I delete the word "First Name" in textarea , the created text box will disappear. I tried many codes already but I can't even make a match function work properly...can I get some hints or help here? Thanks for every reply . Quote Link to comment https://forums.phpfreaks.com/topic/248018-help-with-match-what-i-typed-in-a-textarea/ Share on other sites More sharing options...
freelance84 Posted September 28, 2011 Share Posted September 28, 2011 This will show the hidden field if the value of the text field is identical to the key, else it will hide the other text input: function nameCheck(id,key,id2){ var nameCheck = document.getElementById(id).value; if(nameCheck == key){ document.getElementById(id2).style.display = 'inline'; } else{ document.getElementById(id2).style.display = 'none'; } } <input type="text" id="nameBox" onkeyup="nameCheck('nameBox','FIRST NAME',hiddenBox')"/> <input type="text" id="hiddenBox" style="display:none;"/> This will search the text field for the key and display the other if the key is found and hide of not: function nameCheck(id,key,id2){ var nameCheck = document.getElementById(id).value; if(nameCheck.search(key) > -1 ){ document.getElementById(id2).style.display = 'inline'; } else{ document.getElementById(id2).style.display = 'none'; } } <input type="text" id="nameBox" onkeyup="nameCheck('nameBox','FIRST NAME',hiddenBox')"/> <input type="text" id="hiddenBox" style="display:none;"/> This is not tested. Let me know if it works. Quote Link to comment https://forums.phpfreaks.com/topic/248018-help-with-match-what-i-typed-in-a-textarea/#findComment-1273510 Share on other sites More sharing options...
IreneLing Posted September 28, 2011 Author Share Posted September 28, 2011 Really thanks to your code freelance84 , I get the concept of the function I want now , I'm so confused before I read your reply . However I tried both of the function but it didn't works . I changed the key needed but still the same . Thanks again . Quote Link to comment https://forums.phpfreaks.com/topic/248018-help-with-match-what-i-typed-in-a-textarea/#findComment-1273596 Share on other sites More sharing options...
IreneLing Posted September 28, 2011 Author Share Posted September 28, 2011 Sorry I tried again , ('nameBox','FIRST NAME',hiddenBox') it seems the hiddenBox there miss a ' , i added it and it works . Please allow me to thank you again , it really helps me alot . Thanks freelance84 . Have a nice day . Quote Link to comment https://forums.phpfreaks.com/topic/248018-help-with-match-what-i-typed-in-a-textarea/#findComment-1273621 Share on other sites More sharing options...
IreneLing Posted September 28, 2011 Author Share Posted September 28, 2011 ----------- Quote Link to comment https://forums.phpfreaks.com/topic/248018-help-with-match-what-i-typed-in-a-textarea/#findComment-1273660 Share on other sites More sharing options...
freelance84 Posted September 29, 2011 Share Posted September 29, 2011 Cool, glad it works Quote Link to comment https://forums.phpfreaks.com/topic/248018-help-with-match-what-i-typed-in-a-textarea/#findComment-1273868 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.