Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

js conversion

Status
Not open for further replies.

cumap

IS-IT--Management
Jul 9, 2007
268
US
Could someone help me convert this into a function that I can use/call, my knowledge of js is very limited.
Code:
<script language="javascript" for="PlaybackCtrl" event="ErrorReceived(errorCode, param)">
	// program additional -------------------------------------------------
	var PB_ERR_CONNECT_FAIL		= 0xf0000000;		//  
	var PB_ERR_DISCONNECTED		= 0xf0000001;		//  
	var PB_ERR_SOCKET_ERROR		= 0xf0000002;		//  
	var PB_ERR_NO_VIDEO			= 0xf0000003;		//  
	var PB_ERR_OPEN_FAIL		= 0xf0000020;		//

	var PB_ERR_SOCKET_SEND			= 0xff000001;		//  send 
	var PB_ERR_SOCKET_RECV			= 0xff000002;		// receive 
	var PB_ERR_BODY_SIZE			= 0xff000003;		// body  

	// playback additional ---------------------------------------------------
	var PB_ERR_HDD_NOT_FOUNT		= 0x00040000;
	var PB_ERR_HDD_NOT_ENABLED		= 0x00040001;
	var PB_ERR_OUT_OF_RANGE			= 0x00040002;
	var PB_ERR_IN_SEARCH			= 0x00040004;

	var PB_ERR_OPEN_FILE			= 0xfff00001;

	var bDisconnect = true;
	var error = "";

	alert("ErrorReceived Code "+errorCode);
	switch ( errorCode ) {
	case PB_ERR_CONNECT_FAIL : //  
		error = "Connection failed";
		break;
	case PB_ERR_DISCONNECTED : //  
		error = "Disconnected";
		break;
	case PB_ERR_SOCKET_ERROR : //  
		error = "Socked error";
		break;
	case PB_ERR_NO_VIDEO : //  
		bDisconnect = false;
		error = "No Video";
		break;
	case PB_ERR_HDD_NOT_FOUNT :
		error = "Hdd not founded";
		break;
	case PB_ERR_HDD_NOT_ENABLED :
		error = "Hdd not enabled";
		break;
	case PB_ERR_OUT_OF_RANGE :
		bDisconnect = false;
		error = "Out of range";
		break;
	default:break;
	}

	alert(error);
	if ( error.length ) alert(error);

	if ( bDisconnect && m_bConnect ) {
		m_bConnect = false;
		PlaybackCtrl.Disconnect();
	}
</script>

Thanks!
 
To create a function in JS, you simply wrap your code in a function declaration, like this:

Code:
function functionNameHere(params, go, here) {
   // Code goes here
}

Regarding the script you've given, it looks like it is executed when the "ErrorRecieved" event is fired, which doesn't look like a standard JS thing... so you might need to provide more details about what this is integrating with to know how to harness the event handling without using the "event" attribute on the "script" element itself (or ask in the relevant forum for the product in question).

Or, you could simply frig it to manually call the function at the end of the script, e.g. if you wrapped the whole lot in a function declaration called "myErrorHandler", at the end of the script block, you could simply run the function, passing in the 2 arguments:

Code:
myErrorHandler(errorCode, param);

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Thank you Dan,

You're right! It is a automatic On Error Event that located on the bottom of the whole page which activate when a video is failed or so. I now intend to use it in a different situation which is fired in a IF ELSE case.

For example, I will have this code w/i another function that if the ERROR event is executed, do this, else, do that... But if the event is written in this particular fashion, I don't know how to insert it into the other function like I mentioned on the above. That's where you come in. :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top