0

I have spent about an hour or two trying to find out how to use JavaScript to create a text field when a certain value is selected from a drop down list.

Here is the code for the drop down menu if that's of any help. I'd have attempted to write the code to do this myself, but I am still very unfamiliar with how to write JavaScript code

<select name="claim">
    <option value="">Select a Claim</option>
    <option value="Insurance">Insurance</option> // this option I want when selected to create a text field
    <option value="Warranty">Warranty</option>
</select>

1 Answer 1

2

try this hope it helps

   <div id="area">
         <select id="claim" name="claim">
            <option value="">Select a Claim</option>
        <option value="Insurance">Insurance</option>  
        <option value="Warranty">Warranty</option>
        </select>
        </div>

and script

   $(document).ready(function(){
          $("#claim").change(function(){       
             $("#area").find(".field").remove(); 
             //or
               $('#area').remove('.field');
          if( $(this).val()=="Insurance")
             {
        $("#area").append("<input class='field' type='text' />");

             }
          });

});

example http://jsfiddle.net/cqjJy/

Sign up to request clarification or add additional context in comments.

1 Comment

is there a way if lets say i select the wrong one so inseance but change it to warrenty it will remove the text box instead of leaving it there???

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.