Page 1 of 1

How to handle data in form objects with Vortex and Javascript

Posted: Thu May 05, 2011 5:41 pm
by barry.marcus
I have a form with a number of data entry controls the contents of which are to be saved in a table. One of those is a check box that, via Javascript, disables all of the other fields and controls on the form. (The reason for this is irrelevant to the problem.) The state of the check box is also stored in the table. The way that the code is written now, everything works fine as long as the data entry controls are not disabled. That is, if the check box remains unchecked. But if the check box *is* checked, then the FIRST time the data is saved all is well. But if the data is saved a second time, only the first word of the data in the textarea control is saved.

It seems clear that the problem has something to do with the contents of the hidden control (see example script) being interpreted as an array. But I can't figure out how to fix it.

Below is a simplified example (change the <db> accordingly and create a table named myTest with two varchar fields: hideIt and theData.) Click the Refresh Data button to populate. Notice that as long as you do not click the "Disable text" check box, you can change and save the data successfully as many times as you want. But if you disable the text, save the data, edit the data, then save the data again *WITHOUT ENABLING THE TEXT*, all but the first word of the data in the text area is lost.

Why?!?!

(Anyway, I hope that this makes sense!)

Here is the code (73 lines):

<script language=vortex>

<a name=main>
<urlcp javascript 1>
<db="D:\Crosshairs\database1">
<formLoader>
</a>

<a name=formLoader>
<form name="loaderForm" method="post" action="$url">
<input type="submit" name="cmd" value="Edit Data">
<input type="submit" name="cmd" value="Refresh Data">
</form>
</a>

<a name="showForm">
<verb NOESC>
<script language='Javascript'>
function toggle(idNum) {
var disableSetting = document.getElementById('check' + idNum).checked;
if (disableSetting == true) {
document.getElementById('hid_text' + idNum).value = document.getElementById('text' + idNum).value;
if (document.getElementById('check' + idNum).checked) {
document.getElementById('hid_check' + idNum).value = '1';
} else {
document.getElementById('hid_check' + idNum).value = '0';
}
}
document.getElementById('text' + idNum).disabled = disableSetting;
}
</script>
</verb>

<form name="dataForm" method="post" action="$url">
<if $hideIt eq "1">
<textarea id="text1" name="theData" rows="3" cols="70" wrap="soft" disabled>$theData

How to handle data in form objects with Vortex and Javascript

Posted: Thu May 05, 2011 5:45 pm
by John
It looks like you don't have double quotes around the value in the input type=hidden, so only the first word is the value.

I.e. you should have

<input id="hid_text1" type=hidden name="hid_theData" value="$theData">

How to handle data in form objects with Vortex and Javascript

Posted: Thu May 05, 2011 5:48 pm
by barry.marcus
Argh!!!! John, thank you, thank you! This has been driving me CRAZY all day! I KNEW it had to be some dumb and simple mistake!