Change form input value with Jquery

后端 未结 2 1595
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 03:21

I am trying to change the input field value dynamically when the user pick the options from my dropdown menu. I have tried this code but have no luck. I was wondering if som

相关标签:
2条回答
  • 2020-12-29 03:58

    try :

    $('input[name="project"]').val("Good Fish");
    

    instead of:

    $('input[name="project"]').val()="Good Fish";
    
    0 讨论(0)
  • 2020-12-29 04:04

    The code below should work. I modified the <input> in the html to be formatted correctly as well as changed $('input[name="project"]').val()="Good Fish"; to $('input[name="project"]').val("Good Fish");

    $(document).ready(function(){
        $('select[name="job_number"]').change(function() {
    
            $('input[name="project"]').val("Good Fish");
    
        });
    });
    
    <form action='project_manager' method='post'>
        <input type='text' name='project' value='show Good Fish when user picks an option' />
        <select name='job_number'>
            <option value='1'>job1</option>
            <option value='2'>job2</option>
            <option value='3'>job3</option>
        </select>
    </form>
    
    0 讨论(0)
提交回复
热议问题