Jump to content

SyntaxError: missing ; before statement


pizzipie

Recommended Posts

<script type="text/javascript" >   bakups.onchange=function () {   var x=document.getElementById("bakups").selectedIndex;	var mychoice=document.getElementsByTagName("option")[x].value	   		var is_sure=window.confirm("Are you sure you want to bakup "+ mychoice);	if (is_sure) { 						$.post("DbaseBakup.php", {'mybak': mychoice} , showData, "json");						showData(data) {alert(data)}    // syntax error missing ;	//			showData(retdata) {    // ditto//				alert(retdata);		//			}			//window.alert("OK, you backed up "+mychoice);		return 	false;	}	else {		alert("do something else");		return 	false;	}	}</script>

The code above is what is causing me fits.

 

Error is:

 

Timestamp: 09/17/2013 03:35:27 PMError: SyntaxError: missing ; before statementSource File: http://localhost/DB-Web/testonly/DbaseRestoreTest.phpLine: 53, Column: 21Source Code: showData(retdata) {

 

Any help apperciated.

 

R

Link to comment
Share on other sites

you should read about the syntax for functions

http://www.w3schools.com/js/js_functions.asp

 

now you have the syntax to define a callback function at the top of your script somewhere

function showData(data){  console.log(data);}

then just pass it to $.post like you are currently doing. you shouldn't have to manually call it yourself, but you do have to define it ahead of time.

 

note: logging to the console is often more preferable then alerting. Gives you more detail about the object and doesn't stop page flow with an annoying popup

Edited by thescientist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...