How can I change a form's input value with javascript
-
How can I change a form's input value with javascript depending on witch combobox item is selected. I have a form with some imported values, and there is a field of witch imported value can be changed via a combobox. In my case: print("<input type='hidden' name='issue_array[{$issue["nr"]}][\"supplier\"]' value='{$issue["supplier"]}' />"); I have a combobox, that if I change it's value, should change the value of the input above. This is what I tried: print("<select name='supplier_combo' onchange='setSupplierInputValue(this.value, ${issue['nr']})'>"); and the script: echo "\r\n" . '<SCRIPT TYPE="text/javascript">' . "\r\n"; echo 'function setSupplierInputValue(value, issue_nr)' . "\r\n"; echo '{' . "\r\n"; echo ' issue_array[issue_nr]["supplier"] = value;'; echo '}' . "\r\n"; echo '</SCRIPT>'. "\r\n"; But it doesn't work, please help.
-
Answer:
change your line issue_array[issue_nr]["supplier"] = value; to look like this (you have to select the hidden field by using getElementsByName - or set an id for the hidden field and use getElementById): document.getElementsByName('issue_array['+issue_nr+']["supplier"]')[0].value = value;
Biroka at Stack Overflow Visit the source
Other answers
give the combobox an id for example selection and id for the input say inputExample, so using jquery you can $('#selection').change(function(){ //you get the value using $('#selection option:selected').text() $('#inputExample').val('somevalue you determined'); }) I hope it helps. You can also see the reference on jquery site : http://api.jquery.com/change/
LostMohican
Related Q & A:
- How can I change a value in an array?Best solution by Stack Overflow
- How can I change my friend's name in my friend list?Best solution by Yahoo! Answers
- How can I change a member's name?Best solution by Yahoo! Answers
- How can I change my iPhone's SMS bubble color?Best solution by Yahoo! Answers
- How can I remove a picture's watermark using Matlab's image processing toolbox?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.