Link to home
Start Free TrialLog in
Avatar of dgrafx
dgrafxFlag for United States of America

asked on

html() issue


see this:
<script>
$(document).ready(function() {
      $(".closegroup").live("click", function() {                        
            $('#x2').html($('#x1').html());
      return false;
      });
});
</script>
<a href="" class="closegroup" onclick="return false;">Close</a>
<span id="x1">
<select name="tester" id="tester">
<option value="0">Not Set
<option value="4">4
<option value="5">5
<option value="6">6
</select>
</span><br><br>
<span id="x2" style="border:solid 1px red;">
</span>

select a value from select box then click close
the select box that appears in x2 is reset to not set.
is there a way to retain the value of elements when one does something like this?

keep in mind that this is a real simple ex only and that in real life there would be many form elements.
Avatar of David S.
David S.
Flag of United States of America image

Copying the HTML contents like that recreates the elements each time, so the values of form controls that were modified by the user will be lost.

Do you really need to move the elements? I suggest you consider giving the container "display:none" or absolutely positioning it off the left side of the page.
Avatar of dgrafx

ASKER

I am aware of WHY - I asked if someone knew of some new fangled function ...

What I actually am doing is removing the specified elements from the form scope.
So my second question is how do I remove from form scope - I can then simply hide().
Then show() and how does one put them  back again.

thanks
SOLUTION
Avatar of sunu340
sunu340
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dgrafx

ASKER

i've discovered that values are retained with i.e. 8 (didn't try 7 or ff) but with i.e. 9 values are not retained and i had been testing with 9
i will try disabled - i had assumed that disabled elements were still in the form scope
i'll report back in a few hours
thanks
Avatar of dgrafx

ASKER

ok - you are right is saying that disabled fields are not in the form scope.

so how would one code jquery to disable all form fields within a specific id (<span id="x1">misc form fields</span>)?

thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dgrafx

ASKER

thanks for all the input