Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change form input value with Jquery

Tags:

html

jquery

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 someone here can help me out! Thanks a lot.

$(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'>show Good Fish when user picks an option</input> <select name='job_number'> <option value='1'>job1</option> <option value='2'>job2</option> <option value='3'>job3</option> </select>  </form> 
like image 312
FlyingCat Avatar asked Mar 06 '12 01:03

FlyingCat


People also ask

How to change value of form jQuery?

To get a form value with jQuery, you need to use the val() function. To set a form value with jQuery, you need to use the val() function, but to pass it a new value.

What is val() in jQuery?

jQuery val() Method The val() method returns or sets the value attribute of the selected elements. When used to return value: This method returns the value of the value attribute of the FIRST matched element. When used to set value: This method sets the value of the value attribute for ALL matched elements.

How do you change input value?

Change the Input Value Using the setAttribute() Function in JavaScript. We can also use the setAttribute() function instead of the value property to set the input value. We can also use the forms() function instead of the getElementById() or querySelector() function to get the element using the form name and input name ...

How to get values in jQuery?

jQuery val() method is used to get the value of an element. This function is used to set or return the value. Return value gives the value attribute of the first element. In case of the set value, it sets the value of the attribute for all elements.


1 Answers

try :

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

instead of:

$('input[name="project"]').val()="Good Fish"; 
like image 174
aletzo Avatar answered Oct 12 '22 00:10

aletzo