Below is the code.

My function:
Code:
function swap_content(id1,id2)
{
var tmp = document.getElementById(id1).name;
var theval = document.getElementsByName('primary_propertyp_id')[0].value;
document.getElementById(id1).name = document.getElementsByName('primary_propertyp_id')[0].name;
document.getElementsByName('primary_propertyp_id')[0].name = tmp;
document.getElementById(id2).id = document.getElementById('primary').id;
document.getElementById('primary').id = 'addressid_'+theval+'_div';
}
Applicable Code for primary info:
Code:
<div id="primary">
<label>primary to secondary:</label><input name="primary_propertyp_id" type="text" id="addressid_<? echo $row['primary_property_id']; ?>" value="<? echo $row['primary_property_id']; ?>"/>
</div>
Applicable Code for secondary info/link to change:
Code:
echo "<div id=\"addressid_" . $properties_row['id'] . "_div\">";
echo "<a href=\"#\" onclick=\"swap_content(&apos;addressid_" . $properties_row['id'] . "&apos;,&apos;addressid_" . $properties_row['id'] . "_div&apos;); return false\">Make Primary</a>";
echo "<input id=\"addressid_" . $properties_row['id'] . "\" name=\"addressids[]\" value=\"" . $properties_row['id'] . "\" type=\"text\">";
echo "</div>";
This is running through a PHP loop so it's making multiple divs and links for the secondaries. I am wanting to be able to swap out any of them to make them 'primary'....this works for the first click, but after the first click it makes every div id and input name the same as the first that was clicked.

It's also not working AT all if i click on the bottom link first, then a link above it. Top-down works, bottom-up doesn't...Please help

Thanks in advance,
Jeremy