A
Al Henderson
Morning All,
I am wrestling with some table HTML generated on the fly by javascript
which is then submitted via POST variables and stored in a database.
The code below demonstrates my confusion, and I was hoping someone
could explain it for me.
I have the following javascript to add data to a table via the DOM:
var g_szText = 'Al\'s confused';
var oTblBdy =
document.getElementById("tblTest").getElementsByTagName("tbody")
[0];
if(oTblBdy)
{
var oTR = document.createElement("TR");
if(oTR)
{
var oTD = document.createElement("TD");
var szHTML = "<INPUT TYPE=hidden NAME=hiddentext
ID=hiddentext VALUE='"+g_szText+"'>";
oTD.innerHTML = szHTML;
oTR.appendChild(oTD);
oTblBdy.appendChild(oTR);
}
}
Note the single quote in g_szText. Now, with this as it stands, if I
alert on the value of the hiddentext element it says 'Al', which i can
understand due to the single quote terminating the string. However,
if after setting up the table, I do this:
var oHidden = document.getElementById("hiddentext");
if(oHidden)
{
alert("Hidden text at end of on load: '"+oHidden.value+"'");
oHidden.value = g_szText;
alert("Hidden text after reload: '"+oHidden.value+"'");
}
The second alert here says 'Al's Confused'. And when I submit my
form, the post variable comes back complete, and not truncated. Can
someone explain to me why directly setting the variable value has
different results to setting up the innerHTML of the TD object?
I don't really want to have to reset each of my hidden variables like
that. The problem does not occur if my value goes into a textarea or
a text input box..
Can anyone put me out of my misery?
Thanks,
Al.
I am wrestling with some table HTML generated on the fly by javascript
which is then submitted via POST variables and stored in a database.
The code below demonstrates my confusion, and I was hoping someone
could explain it for me.
I have the following javascript to add data to a table via the DOM:
var g_szText = 'Al\'s confused';
var oTblBdy =
document.getElementById("tblTest").getElementsByTagName("tbody")
[0];
if(oTblBdy)
{
var oTR = document.createElement("TR");
if(oTR)
{
var oTD = document.createElement("TD");
var szHTML = "<INPUT TYPE=hidden NAME=hiddentext
ID=hiddentext VALUE='"+g_szText+"'>";
oTD.innerHTML = szHTML;
oTR.appendChild(oTD);
oTblBdy.appendChild(oTR);
}
}
Note the single quote in g_szText. Now, with this as it stands, if I
alert on the value of the hiddentext element it says 'Al', which i can
understand due to the single quote terminating the string. However,
if after setting up the table, I do this:
var oHidden = document.getElementById("hiddentext");
if(oHidden)
{
alert("Hidden text at end of on load: '"+oHidden.value+"'");
oHidden.value = g_szText;
alert("Hidden text after reload: '"+oHidden.value+"'");
}
The second alert here says 'Al's Confused'. And when I submit my
form, the post variable comes back complete, and not truncated. Can
someone explain to me why directly setting the variable value has
different results to setting up the innerHTML of the TD object?
I don't really want to have to reset each of my hidden variables like
that. The problem does not occur if my value goes into a textarea or
a text input box..
Can anyone put me out of my misery?
Thanks,
Al.