1

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.

1
  • You could probably significantly simplify the thing you're trying to do, e.g. with Smarty template engine to avoid hard-coded markup. Commented Jun 14, 2010 at 9:35

2 Answers 2

2

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;
Sign up to request clarification or add additional context in comments.

Comments

0

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/

Comments

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.