Jump to content

Help with match() what I typed in a textarea


IreneLing

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 .

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.