furious70
12-16-2003, 11:06 AM
In the same code as in this thread http://forums.webdeveloper.com/showthread.php?s=&postid=122678#post122678
I'm having a problem with accessing the children. This screen can be either started in 'new' entry form, whereas the 'oracle_order_num' field is not shown, or in an edit/copy mode, whereas the o_o_n field may be shown (and populated). In either mode, the user has the option to toggle (either say I need that field or I don't need that field).
When the form is brought up in blank mode (field not present) you can toggle all day long and everything is good. If brought up in edit/copy, you can toggle out (make the label and input box disappear), toggle back into needing the box (it'll be blank now however), but when you toggle to remove the box the 2nd time, the label disappears, but the box stays, and now that extra box is always present. (Does not add an extra box per toggle).
I could not get a loop through the childnodes to work, so I did a hack job of using .firstChild. It is noted in the code.
If someone can help with the correct loop, that would be much better.
The HTML that sets the box up:
<cfif IsDefined("session.#attributes.order#.oracle_order_num") AND
session["#attributes.order#"].oracle_order_num neq "">
<script>
var smp_cell = document.getElementById('smp_cell');
smp_cell.setAttribute('width','33%');
</script>
<td style="background-color: white; width: 33%; align: center;" id="oracle_number_cell" nowrap>
Oracle Order Number: <input type="text" name="oracle_order_num" size="7"
value="#session["#attributes.order#"].oracle_order_num#" maxlength="7">
</td>
<cfelse>
<td style="background-color: gray; width: 1; align: center;" id="oracle_number_cell" nowrap></td>
</cfif>
the JS function called to do the toggle:
function oracleOrder()
{
//This function works as a toggle, showing or hiding the necessary
//elements for an oracle order
oracle_order_num_error.innerHTML = ""
var oracle_number_cell = document.getElementById('oracle_number_cell');
var smp_cell = document.getElementById('smp_cell');
var mne_cell = document.getElementById('mne_cell');
var orig_coreid_box = document.getElementById('orig_coreid');
var orig_pager_box = document.getElementById('orig_pager');
var orig_name_box = document.getElementById('orig_name');
var orig_phone_box = document.getElementById('orig_phone');
var orig_email_box = document.getElementById('orig_email');
if (is_oracle == false)
{
//reset table cells
smp_cell.style.width = '33%';
mne_cell.style.width = '33%';
oracle_number_cell.style.backgroundColor = 'fff';
oracle_number_cell.style.align = 'center';
oracle_number_cell.style.width = '33%';
//blank out orig
orig_coreid_box.setAttribute('value','');
orig_pager_box.setAttribute('value','');
orig_name_box.setAttribute('value','');
orig_phone_box.setAttribute('value','');
orig_email_box.setAttribute('value','');
var tdText=document.createTextNode('Oracle Order Number: ');
var oracle_order_num = document.createElement('input');
oracle_order_num.setAttribute('type','text');
oracle_order_num.setAttribute('name','oracle_order_num');
oracle_order_num.setAttribute('value','');
oracle_order_num.setAttribute('size','7');
oracle_order_num.setAttribute('maxlength','7');
oracle_number_cell.appendChild(tdText);
oracle_number_cell.appendChild(oracle_order_num);
oracle_link.innerHTML = "<a href='javascript:oracleOrder()'>This is not an Oracle Order</a>";
}
else
{
//we must remove the children that are built in the if
//should be able to loop through oracle_number_cell.childnodes, but had to do it like
//this to make it work
oracle_number_cell.removeChild(oracle_number_cell.firstChild);
oracle_number_cell.removeChild(oracle_number_cell.firstChild);
smp_cell.style.width = '50%';
mne_cell.style.width = '50%';
oracle_number_cell.style.width = '1';
oracle_number_cell.setAttribute('bgcolor','gray');
oracle_number_cell.style.backgroundColor = '777'
//fill orig back in
orig_coreid_box.setAttribute('value',orig_coreid);
orig_pager_box.setAttribute('value',orig_pager);
orig_name_box.setAttribute('value',orig_name);
orig_phone_box.setAttribute('value',orig_phone);
orig_email_box.setAttribute('value',orig_email);
oracle_link.innerHTML = "<a href='javascript:oracleOrder()'>This is an Oracle Order</a>";
}
is_oracle = !is_oracle;
}
I'm having a problem with accessing the children. This screen can be either started in 'new' entry form, whereas the 'oracle_order_num' field is not shown, or in an edit/copy mode, whereas the o_o_n field may be shown (and populated). In either mode, the user has the option to toggle (either say I need that field or I don't need that field).
When the form is brought up in blank mode (field not present) you can toggle all day long and everything is good. If brought up in edit/copy, you can toggle out (make the label and input box disappear), toggle back into needing the box (it'll be blank now however), but when you toggle to remove the box the 2nd time, the label disappears, but the box stays, and now that extra box is always present. (Does not add an extra box per toggle).
I could not get a loop through the childnodes to work, so I did a hack job of using .firstChild. It is noted in the code.
If someone can help with the correct loop, that would be much better.
The HTML that sets the box up:
<cfif IsDefined("session.#attributes.order#.oracle_order_num") AND
session["#attributes.order#"].oracle_order_num neq "">
<script>
var smp_cell = document.getElementById('smp_cell');
smp_cell.setAttribute('width','33%');
</script>
<td style="background-color: white; width: 33%; align: center;" id="oracle_number_cell" nowrap>
Oracle Order Number: <input type="text" name="oracle_order_num" size="7"
value="#session["#attributes.order#"].oracle_order_num#" maxlength="7">
</td>
<cfelse>
<td style="background-color: gray; width: 1; align: center;" id="oracle_number_cell" nowrap></td>
</cfif>
the JS function called to do the toggle:
function oracleOrder()
{
//This function works as a toggle, showing or hiding the necessary
//elements for an oracle order
oracle_order_num_error.innerHTML = ""
var oracle_number_cell = document.getElementById('oracle_number_cell');
var smp_cell = document.getElementById('smp_cell');
var mne_cell = document.getElementById('mne_cell');
var orig_coreid_box = document.getElementById('orig_coreid');
var orig_pager_box = document.getElementById('orig_pager');
var orig_name_box = document.getElementById('orig_name');
var orig_phone_box = document.getElementById('orig_phone');
var orig_email_box = document.getElementById('orig_email');
if (is_oracle == false)
{
//reset table cells
smp_cell.style.width = '33%';
mne_cell.style.width = '33%';
oracle_number_cell.style.backgroundColor = 'fff';
oracle_number_cell.style.align = 'center';
oracle_number_cell.style.width = '33%';
//blank out orig
orig_coreid_box.setAttribute('value','');
orig_pager_box.setAttribute('value','');
orig_name_box.setAttribute('value','');
orig_phone_box.setAttribute('value','');
orig_email_box.setAttribute('value','');
var tdText=document.createTextNode('Oracle Order Number: ');
var oracle_order_num = document.createElement('input');
oracle_order_num.setAttribute('type','text');
oracle_order_num.setAttribute('name','oracle_order_num');
oracle_order_num.setAttribute('value','');
oracle_order_num.setAttribute('size','7');
oracle_order_num.setAttribute('maxlength','7');
oracle_number_cell.appendChild(tdText);
oracle_number_cell.appendChild(oracle_order_num);
oracle_link.innerHTML = "<a href='javascript:oracleOrder()'>This is not an Oracle Order</a>";
}
else
{
//we must remove the children that are built in the if
//should be able to loop through oracle_number_cell.childnodes, but had to do it like
//this to make it work
oracle_number_cell.removeChild(oracle_number_cell.firstChild);
oracle_number_cell.removeChild(oracle_number_cell.firstChild);
smp_cell.style.width = '50%';
mne_cell.style.width = '50%';
oracle_number_cell.style.width = '1';
oracle_number_cell.setAttribute('bgcolor','gray');
oracle_number_cell.style.backgroundColor = '777'
//fill orig back in
orig_coreid_box.setAttribute('value',orig_coreid);
orig_pager_box.setAttribute('value',orig_pager);
orig_name_box.setAttribute('value',orig_name);
orig_phone_box.setAttribute('value',orig_phone);
orig_email_box.setAttribute('value',orig_email);
oracle_link.innerHTML = "<a href='javascript:oracleOrder()'>This is an Oracle Order</a>";
}
is_oracle = !is_oracle;
}