If you wish to set the value of a form field based upon the value put in another field here is one way to do it.
I recommend you use a field with set values to pick from to make it easier. My example uses a field where the values are Yes and No. The file you modify is the tablename_templateDV.html. I have done this using jquery.
At the very bottom you would add text similar to the following using your values.
Code: Select all
<script>
$j(document).ready(function(){
$j('#position').change(function(){
var positionvalue = ($j('#position').val());
if(!positionvalue || positionvalue == 'Yes'){
$j('#points').val("2");
}else{
$j('#points').val("1");
}
});
});
</script>
<script> this line announces what follows is a script
$j(document).ready(function(){ - this is the jquery document ready function
$j('#position').change(function(){ - this line watches for the field to change
var positionvalue = ($j('#position').val()); - this line put the value of the field called postion into the variable positionvalue - gets content of field
if(!positionvalue || positionvalue == 'Yes'){ - this line is the start of the if function. Tests to see if the variable postionvalue equals Yes
$j('#points').val("2"); - if yes it puts in a 2 into the field called points.
Then next line then puts in a 1 if it is not equal to yes using the if then else construct.
</script> - closes the script section.
You may wish to turn off the ability to edit the field so the user cannot change the input but you can put a value in. I have another topic which covers how to do that. (Not sure which one right now).
There is a tighter way to do it but this method is fairly easy to follow and allow everyone to make easy changes to suit their needs.
Enjoy
Alan