Results 1 to 2 of 2

Thread: Java Script Not Working?

Hybrid View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2008
    Location
    Reading, UK
    Posts
    192

    Java Script Not Working?

    Hi there

    Im having a bit of a problem getting some Javascript on my html page working properly

    This is my Html File

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="javascripts/jquery-1.9.0.js" type="text/javascript"></script>
    <title>Invoices</title>
    	
    </head>
    <body>
    	<Script type="text/javascript">
    	function GetVehicles(){
    		$(function(){
    			var regpart=document.getElementsByName('serstr')[0].value;
    			var items="<option value='0'></option>";
    			$.getJSON("phpscripts/refreshvehicles.php?a="+regpart,function(data){
    				var item="";
    				$.each(data,function(index,item){
    					items+="<option value='"+item.VehicleId+"'>"+item.Vehicle+"</option>";
    				});
    				$("#a1_vehicle").html(items);
    			});
    		});
    	}
    	function GetInvoices(sel)
    	{
    		$(function(){
    			var vid=sel.options[sel.selectedIndex].value;
    			var items="<p>"+vid+"</p><br>";
    			items+="<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\">";
    			items+="<tr><th>Invoice Number</th><th>Invoice Date</th><th>Amount</th></tr>";
    			$.getJSON("phpscripts/getinvoices.php?a="+vid,function(data){
    				var nitem="";				
    				$.each(data,function(index,nitem){
    					items+="<tr><td>"+nitem.InvoiceNumber+"</td><td>"+nitem.InvoiceDate+"</td><td>"+nitem.Amount+"</td></tr>";
    				});
    			});
    			items+="</table>"
    			$("#a1_invoice").html(items);
    		});
    	}
    	</script>
    	<form>
    		<fieldset>
    			<legend>Select Vehicle</legend>
    			<input type='hidden' name='submitted' id='submitted' value='1'/>
    			<label for='serstr' >Vehicle:</label><br>
    			<input type='text' name='serstr' id='serstr'  maxlength="50"/><br>
    			<input onclick="GetVehicles()" type='button' name='Filter' value='Filter'/><br>
    			<label  for='vehicles' >Vehicle:</label><br>
    			<select onchange="GetInvoices(this)" id="a1_vehicle" name="a1_vehicle">
    				<option>Default</option>
    			</select>
    		</fieldset>
    	</form>
    	<div id="a1_invoice" name="a1_invoice">
    	</div>
    </body>
    </html>
    My Php Script definatly works and echos the JSON as expected see here
    but id say its the $.getJSON("phpscripts/getinvoices.php?a="+vid,function(data) bit thats not working as i have played around putting other Html Rows in during that section and they haven't come out

    Many thanks for any help

    Ian

  2. #2
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: Java Script Not Working?

    See my reply to http://www.vbforums.com/showthread.p...=1#post4326329 for tips which might help. Also, the web browser development tools are a great help in debugging javascript, allowing you to set breakpoints on the code and see javascript errors in the script console.

    Google Chrome has built-in "Developer Tools" accessible from the settings menu, as does Safari. Firebug has built-in tools and also the great Firebug extension. Opera has the built-in Dragonfly tools similar to Chrome's developer tools.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

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



Click Here to Expand Forum to Full Width