Welcome Guest, Not a member yet? Register   Sign In
Javascript - array of objects, exchage values
#2

[eluser]teampoop[/eluser]
Probably your best approach would be to set all of the hidden fields to zero, then assign the selected one the correct value. I am assuming you have the following
Code:
<ul class="the_links">
  <li><a href="link" id="link_l">link 1</a></li>
  <li><a href="link" id="link_2">link 2</a></li>
  <li><a href="link" id="link_3">link 3</a></li>
</ul>

<div class="places">
  &lt;input type="hidden" name="link_1" value="0"&gt;
  &lt;input type="hidden" name="link_2" value="1"&gt;
  &lt;input type="hidden" name="link_3" value="2"&gt;
</div>

Your JS would be something like so:
Code:
$("a", ".the_links").click(function(){
  $a = $(":hidden", ".places");  // gets your nodes
  $a.each(function(){ $(this).val(0);});  // sets all to zero
  $a.find("[name="+$(this).attr('id')+"}").val(1);  // finds proper name and sets value
});

Now this is just a quick thought and I haven't tested it, but I think it's on the right track.

HTH


Messages In This Thread
Javascript - array of objects, exchage values - by El Forum - 12-14-2010, 09:49 AM
Javascript - array of objects, exchage values - by El Forum - 12-14-2010, 10:42 AM
Javascript - array of objects, exchage values - by El Forum - 12-14-2010, 11:30 AM
Javascript - array of objects, exchage values - by El Forum - 12-15-2010, 06:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB