By enboig on
I am developing a module with form with lots of options, and some of them just have sense depending on the others.
The first approach was to make a multistep form, but now I am trying to use javascript to make some options appear/desapear depending on the other ones. I tryied to follow the example at http://drupal.org/node/189481 but I am really lost at how to add javascript to a form and how to access the form content.
My code is:
drupal_add_js ("$(document).ready(
function() {
$('form-div-proves').change(
function() {
alert('canvi!!!!');
}
);
}
);");
$form['proves'] = array(
'#type' => 'select',
'#title' => t('proves'),
'#options' => array(1=>'a',2=>'b',3=>'c'),
'#weigth' => -9,
);
But what get is:
<script type="text/javascript" src="/ccc/$(document).ready(
function() {
$(& # 0 3 9 ;form-div-proves& # 0 3 9 ;).change(
function() {
alert(& # 0 3 9 ; canvi!!!!& # 0 3 9 ;);
}
);
}
);"></script>
.......
<div><div class="form-item">
<label for="edit-proves">proves: </label>
<select name="proves" class="form-select" id="edit-proves" ><option value="1">a</option><option value="2">b</option><option value="3">c</option></select>
</div>
I don't know why " or ' get translated to html, and how to access "proves" and depending of its value mark other fields as visible.
Any hint is wellcome, thanks
PD: I "spaced" & # 0 3 9 ; it appear joined in browser code.
Comments
second paramenter "inline"
now " gets translated
now " gets translated correctly, thanks.
I will "play" until I find how to access the form fields.
La vida és una taronja, què esperes per exprimir-la?
Now I get when the field is
Now I get when the field is changed, but I don't know how to catch the value (in order to make un switch and just show the fiels I want...).
The code right now is:
La vida és una taronja, què esperes per exprimir-la?
I correct myself, the code
I correct myself, the code is:
La vida és una taronja, què esperes per exprimir-la?