Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2013
    Posts
    157
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Exclamation .html() function & .append() function Question *edited*

    Im drawing data from a php file based on a query that runs with a value selected in a dropdown on a form.

    It displays data correctly, however I want to display <option>--</option> AND THEN the data from the php file.

    Can i do something like

    Code:
    $("#field_provider").html('<option>--</option>', data);
    That doesnt work but just so you know what Im trying to do.

    *edit* I also tried the append() function which from what I understood should not overwrite the data I already have in the id , instead should add the data to the end of the id.

    Code:
    $("#field_provider").append(data);
    However is still overwriting what I have in there already.

    This is the code currently..

    Code:
    <script type="text/javascript">
    	
    	function getItems(){	
    		$("#field_provider").html('');
    		$.post("caller.php",{ 
    			functionCall: "getItems"
    			,dropdownvalueone: $("#field_type").val()
    			,dropdownvaluetwo: $("#field_manu").val()
    		}, function(data) {
    			$("#field_provider").append(data);
    			getValues();
    		});
    	}
    	
    	function getValues(){ 
    		if($("#field_item").val()!='--'){
    			$.post("caller.php",{ 
    				functionCall: "getValues"
    				,dropdownvalue: $("#field_item").val()
    				,dropdownvaluefour: $("#field_provider").val()
    			}, function(data) {	
    				$("#field_cond").append(data);
    			});  
    		}else{
    			$("#field_cond").html('<option value="--">--</option>');
    			$("#field_price").val('');
    		}
    	}	
    
    function getValuesthree(){	
    		$("#field_item").html('');
    		$.post("caller.php",{ 
    			functionCall: "getValuesthree"
    			,dropdownvalueone: $("#field_type").val()
    			,dropdownvaluetwo: $("#field_manu").val()
    			,dropdownvaluethree: $("#field_provider").val()
    		}, function(data) {
    			$("#field_item").append(data);
    			getValues();
    		});
    	}
    	
    	function getValue(){
    		$("#field_price").val($("#field_cond").val());
    	}
    	
    </script>
    Last edited by 7daytheory; 11-17-2013 at 03:57 AM. Reason: New Info

  • #2
    Regular Coder
    Join Date
    Aug 2013
    Posts
    157
    Thanks
    23
    Thanked 0 Times in 0 Posts
    *edit* tried append function, from what I understand append function should input data AFTER what is already inputted. But is overwriting.

  • #3
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,220
    Thanks
    23
    Thanked 606 Times in 605 Posts
    Code:
    function getItems(){
    	$("#field_provider").html(''); //THIS LINE IS KILLING THE CONTENTS OF YOUR LIST 
    	$.post("caller.php",{
    		functionCall: "getItems"
    		,dropdownvalueone: $("#field_type").val()
    		,dropdownvaluetwo: $("#field_manu").val()
    	}, function(data) {
    		$("#field_provider").append(data);
    		getValues();
    	});
    }
    If you remove the line marked above you will get your wanted append to work.
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •