lundi 26 avril 2021

Getting a value to mirror another value

I am trying to make it so field2 will display whatever value is input in field1. I am using an onchange event to do this.

field1 is an input text box so if field1= "Mary", field2 should read "Mary".

If field1 says "Peanut Butter and Jelly" field2 should say "Peanut Butter and Jelly".

If field1 is left blank, field2 should be left blank.

Right now I have a code that makes field2 replicate field1, but I have to give it a set of predetermined values where I want to have the code function so that users are not limited to options I supply for giving input.

this works tight now:

if (filed1.value=='Hello') {filed2.value='Hello'} else {filed2.value='';}

what I need it to say is

if (field1.value=='anything at all') {filed2.value='whatever was put in filed1'}

else {field2.value='';}

Aucun commentaire:

Enregistrer un commentaire