Retreiving values of form elements after being changed by DOM

A

Angel

I have an html form with checkboxes in different rows. The
functionality is that of changing the position of the checkboxes
through DOM.

When I try to save the form after the changes, firefox doesnt recognize
the checkbox element whose position was changed.

How do i retrieve the value of the checkbox whose position was changed?
 
R

Richard Cornford

Angel said:
I have an html form with checkboxes in different rows. The
functionality is that of changing the position of the checkboxes
through DOM.

When I try to save the form after the changes, firefox doesnt
recognize the checkbox element whose position was changed.

How do i retrieve the value of the checkbox whose position was
changed?

Generally Firefox functions near flawlessly so without a demonstration
of the code that you are having trouble with there will not be a great
deal that anyone can say towards resolving any issues it provokes.

Richard.
 
A

Angel

Richard said:
Generally Firefox functions near flawlessly so without a demonstration
of the code that you are having trouble with there will not be a great
deal that anyone can say towards resolving any issues it provokes.

Richard.

Consider the following table

<form>
<table width="50%" border="1" cellpadding="0" cellspacing="0"
bordercolor="#CCCCCC" id="myTable" name="myTable">
<tr id="1">
<td> <input name="radiobutton" type="radio"
value="radiobutton">1 </td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr id="1">
<td width="11%">&nbsp;</td>
<td width="28%"><input type="checkbox" name="checkbox"
value="checkbox1" >Checkbox 1 </td>
<td width="28%">&nbsp;</td>
</tr>
<tr id="2">
<td><input name="radiobutton" type="radio"
value="radiobutton">2</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr id="2">
<td width="11%">&nbsp;</td>
<td width="28%"><input type="checkbox" name="checkbox"
value="checkbox2">Checkbox 2 </td>
<td width="28%">&nbsp;</td>
</tr>
</table>
</form>

On click of checkbox2 i write a function to move its position in the td
next to checkbox1

After doing so, i call the following function :

function myFunc()
{
var v = document.forms[0].elements['checkbox'];
for(i=0; i<v.length; i++)
alert(v.value);
}

Firefox doesnt alert "checkbox2"

Hope I make sense!
 
R

RobG

Angel said:
Consider the following table

<form>

The action attribute is required.

<table width="50%" border="1" cellpadding="0" cellspacing="0"
bordercolor="#CCCCCC" id="myTable" name="myTable">

Table's don't have either a bordercolor or name attribute: bordercolor
does not belong to HTML 4 at all.
<tr id="1">

The id attribute must start with a letter, not a number - though I think
most browsers will tolerate numbers it isn't valid markup.

<td> <input name="radiobutton" type="radio"
value="radiobutton">1 </td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr id="1">

The id attribute must be unique within a document, using getElementById
will likely always return the first element with the duplicate id.

You may find your problem related to the above.

[...]
On click of checkbox2 i write a function to move its position in the td
next to checkbox1

After doing so, i call the following function :

function myFunc()
{
var v = document.forms[0].elements['checkbox'];
for(i=0; i<v.length; i++)
alert(v.value);
}

Firefox doesnt alert "checkbox2"


It does for me. Try:

<script type="text/javascript">
function moveMe(el)
{
var tBody = el.parentNode.parentNode.parentNode;
var td = tBody.rows[1].cells[2];
td.appendChild(el);
myFunc();
}

function myFunc()
{
var v = document.forms[0].elements['checkbox'];
for(i=0; i<v.length; i++)
alert(v.value);
}
</script>

<form action="">
<table border="1" id="myTable">
<tr>
<td><input name="radiobutton" type="radio"
value="radiobutton">1</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr><tr>
<td>&nbsp;</td>
<td><input type="checkbox" name="checkbox"
value="checkbox1" >Checkbox 1 </td>
<td>&nbsp;</td>
</tr><tr>
<td><input name="radiobutton" type="radio"
value="radiobutton">2</td>
<td></td>
<td></td>
</tr><tr>
<td></td>
<td><input type="checkbox" name="checkbox"
value="checkbox2"
onclick="moveMe(this);"
Checkbox 2 </td>
<td></td>
</tr>
</table>
</form>
 
A

Angel

RobG said:
Angel said:
Consider the following table

<form>

The action attribute is required.

<table width="50%" border="1" cellpadding="0" cellspacing="0"
bordercolor="#CCCCCC" id="myTable" name="myTable">

Table's don't have either a bordercolor or name attribute: bordercolor
does not belong to HTML 4 at all.
<tr id="1">

The id attribute must start with a letter, not a number - though I think
most browsers will tolerate numbers it isn't valid markup.

<td> <input name="radiobutton" type="radio"
value="radiobutton">1 </td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr id="1">

The id attribute must be unique within a document, using getElementById
will likely always return the first element with the duplicate id.

You may find your problem related to the above.

[...]
On click of checkbox2 i write a function to move its position in the td
next to checkbox1

After doing so, i call the following function :

function myFunc()
{
var v = document.forms[0].elements['checkbox'];
for(i=0; i<v.length; i++)
alert(v.value);
}

Firefox doesnt alert "checkbox2"


It does for me. Try:

<script type="text/javascript">
function moveMe(el)
{
var tBody = el.parentNode.parentNode.parentNode;
var td = tBody.rows[1].cells[2];
td.appendChild(el);
myFunc();
}

function myFunc()
{
var v = document.forms[0].elements['checkbox'];
for(i=0; i<v.length; i++)
alert(v.value);
}
</script>

<form action="">
<table border="1" id="myTable">
<tr>
<td><input name="radiobutton" type="radio"
value="radiobutton">1</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr><tr>
<td>&nbsp;</td>
<td><input type="checkbox" name="checkbox"
value="checkbox1" >Checkbox 1 </td>
<td>&nbsp;</td>
</tr><tr>
<td><input name="radiobutton" type="radio"
value="radiobutton">2</td>
<td></td>
<td></td>
</tr><tr>
<td></td>
<td><input type="checkbox" name="checkbox"
value="checkbox2"
onclick="moveMe(this);"
Checkbox 2 </td>
<td></td>
</tr>
</table>
</form>



Thanks for all the help Rob

Regards,
Angel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top