Forums

Adding attributes to form elements

chriso0258 25 May, 2012
I'm currently using the drop down selection box provided in ChronoForms. Because of some javascript I'm adding, the select element needs to look like this:

<select onchange="Disable(this,'add','delete');" >


Is there a way to add this onchange attribute using the current drop down box, or do I need to delete the drop down box and add the box using the custom html element?
GreyHead 25 May, 2012
Hi chriso0258 ,

Please try this in a Load JS action instead:
window.addEvent('domready', function() {
  $('select_id').addEvent('change', Disable(this, 'add', 'delete'));
});
You need to add the select id and 'this' may need to be changed.

Bob
chriso0258 25 May, 2012
I've added your code and the Add/Delete Members button are diabled. However, they remain disabled on any option. I probably don't have a correct variable in place.

The id for the selection box is:
<select id="membership" class=" validate['required']" name="membership" title="" size="1">


The id for the Add/Remove Members and adding rows custom html code is 'personal_info'. The custom code for the Add/Delete Members button is:
<INPUT name="add" disabled="disabled" type="button" value="Add Member" onclick="addRow('dataTable')" />

<INPUT name="delete" disabled="disabled" type="button" value="Delete Member" onclick="deleteRow('dataTable')" />


And the JS code in the Load JS action I'm using including your code is:
window.addEvent('domready', function() {
  $('membership').addEvent('change', Disable(this, 'add', 'delete'));
});

function Disable(s,d1,d2){
 var frm=s.form;
 frm[d1].disabled='disabled';
 frm[d2].disabled='disabled';
 if (s.value&&s.value>10){
  frm[d1].removeAttribute('disabled');
  frm[d2].removeAttribute('disabled');
 }
}


I have not included the JS code for adding the rows since that part is working, however it is in the Load JS action as well.
GreyHead 26 May, 2012
Hi chris0258,

I'm not sure I follow your code but try using
frm[d1].setProperty('disabled', true); and frm[d1].setProperty('disabled', false);

Personally I'd add ids to the inputs and then use $(d1) to identify them.

Bob
This topic is locked and no more replies can be posted.