I am going out of my mind with what I would typically believe to be a trivial problem...
I have a page with a form. In the form I have a selection box and a few text boxes. When I change the selection box value to zero it should clear the text boxes, and when I change the selection box to any other value it sets the text boxes to other values (which it gets from an ajax call). This all works fine using the following code which I call from my jQuery document.ready event handler.
Code:
if($("select#myselboxID").val() != 0){ // if my selection box value is not zero
$.ajax({ type: "POST", url: "includes/ajax/getDetails.php?id=" + $("select#myselboxID").val(), dataType: "xml", success: function(xml){
$("form input#name").attr("Value", $(xml).find('name').text());
$("form input#phone").attr("Value", $(xml).find('phone').text());
$("form input#email").attr("Value", $(xml).find('email').text());
$("form textarea#_address").text($(xml).find('address').text());
}});
}
else{ // if my selection box value is zero
$("form input#name").attr("Value", "");
$("form input#phone").attr("Value", "");
$("form input#email").attr("Value", "");
$("form textarea#address").text("");
}
So with the above I can make my form values clear and change to other values etc to my hearts content. However if I go down and manually edit a text box value and then change the value in the selection box, the value I manually set the textbox to stays there and only the other non edited textbox fields change. When really I want all textbox entries to change regardless of whether or not I manually modified them.
Could someone please explain to me why this is happening? I feel like there is something significant about how a browser works with form values that I'm clearly unaware of.
Many Thanks ;)