Jump to content

Recommended Posts

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 .

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.

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 .

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 .

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.