Below is a complete example document. It's strung together and not
organized like a real implementation should be, but shows you a way to
grab an associated label for an element and tack on a new hidden form
element to pass it along as though it was there all along.
Watch out for line wrapping.
J Wynia
Myriad Intellect, Inc.
"Web technology that earns its keep."
www.myriadintellect.com
------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<script language="JavaScript">
<!--
function submit_labels(){
//Gather information from the form and the element in question
//A more abstract version of this function should really be used where the
//form is submitted and all labels synced up with matching hidden values.
$form = document.getElementById("products");
$product = document.getElementById("product1");
$label_id = "label_" + $product.id;
$label = document.getElementById($label_id);
$label_value = $label.innerHTML;
//Take our gathered info and append a hidden element to the form for the
label.
var $new_element = document.createElement("<input>");
$new_element.setAttribute('type', 'hidden');
$new_element.setAttribute('name', $label_id);
$new_element.setAttribute('value', $label_value);
$form.appendChild($new_element);
return true;
}
//-->
</script>
</head>
<body>
<form id ="products" name="products"
action="http://www.phpgeek.com/util/formdump.php" method="get"
onsubmit="submit_labels();">
<label for="product1" id="label_product1">bread</label>
<input id="product1" name="product1" type="text" size="3">
<input type="submit">
</form>
</body>
</html>