How to: JavaScript onClick button

I have to put the code below in a button (onClick). What do I need to add to it to make notes accept it in design?

Var appName=“Demo ADISMembership”;

Var userID=“”;

Var password=“”;

Var inputArray();

inputArray(0)=userID;

inputArray(1)=password;

inputArray(2)=appName;

var balancedUrl=XMLRPC.call(“https://vwtest.oas.psu.edu/isapi/gi.dll/rpc2","getBalancedURL”,inputParams);

document.write(balancedUrl);

Subject: How to: JavaScript onClick button

i see a few things wrong here:

  1. Javascript is case-sensitive, so use “var” instead of “Var”

  2. Your array declaration is invalid, use this instead:

var inputArray = new Array();

  1. Array indexes should be referenced with square brackets, not round.

So here is your code corrected:

var appName=“Demo ADISMembership”;

var userID=“”;

var password=“”;

var inputArray = new Array(3);

inputArray[0]=userID;

inputArray[1]=password;

inputArray[2]=appName;

var balancedUrl=XMLRPC.call(“https://vwtest.oas.psu.edu/isapi/gi.dll/rpc2","getBalancedURL”,inputParams);

document.write(balancedUrl);

Subject: RE: How to: JavaScript onClick button

Thank you, Jason. Do you know why when I add my next line of code then I get the “missing ; before statement” error? Here is the next bit of code:

var startTransParams();

startTransParams[0]=userID; 'appliction service id

startTransParams[1]=password;

startTransParams[2]=appName;

startTransParams[3]=“802004901”; 'merchant Number

startTransParams[4]=“5.00” 'Amount

startTransParams[5]=“0.00” 'Tax

startTransParams[6]=“userID” 'user purchasing membership

startTransParams[7]=“Alumni Membership Fee” 'Description

startTransParams[8]=“UP” 'Location

startTransParams[9]=“https://yourreturnURL.com” 'return URL

startTransParams[10]=“Y” ’ Auto deposit flag

var starttransresponse=XMLRPC.call(balancedUrl,“startPSUPayTransaction”,startTransParams)

var transactionId=startTransResponse[4]

document.write(transactionId); 'Display transactionID. Needs to be 'stored some where

I am placing this directly under the last piece of code. Thanks!

Subject: RE: How to: JavaScript onClick button

Well, putting in a number of semicolons might help. You lost them half way through your array. Every statement should end in a semicolon.

Subject: RE: How to: JavaScript onClick button

Thank you, Harkpabst. I have added the semicolons and am still getting the error. It seems to not like the line:var startTransParams();

That line gets highlighted in red and I see the error “missing ; before statement”) I don’t see that I’m missing anymore semicolons and I commented out the comments with // rather than ’ as I had. I’ve never used JavaScript before. Any ideas?

var appName=“Demo ADISMembership”;

var userID=“”;

var password=“”;

var inputArray = new Array(3);

inputArray[0]=userID;

inputArray[1]=password;

inputArray[2]=appName;

var balancedUrl=XMLRPC.call(“https://vwtest.oas.psu.edu/isapi/gi.dll/rpc2","getBalancedURL”,inputParams);

document.write(balancedUrl);

var startTransParams();

startTransParams[0]=userID; //appliction service id

startTransParams[1]=password;

startTransParams[2]=appName;

startTransParams[3]=“802004901”; //merchant Number

startTransParams[4]=“5.00”; //Amount

startTransParams[5]=“0.00”; //Tax

startTransParams[6]=“userID”; //user purchasing membership

startTransParams[7]=“Alumni Membership Fee”; //Description

startTransParams[8]=“UP”; //Location

startTransParams[9]=“https://yourreturnURL.com”; //return URL

startTransParams[10]=“Y”; //Auto deposit flag

var starttransresponse=XMLRPC.call(balancedUrl,“startPSUPayTransaction”,startTransParams);

var transactionId=startTransResponse[4];

document.write(transactionId); //Display transactionID. Needs to be stored some where

Subject: Why do you have parens?

var startTransParams();

Why the () ?

Are you defining an array?

var startTransParams = new Array()

Subject: RE: Why do you have parens?

Thank you, Carl. I almost missed your post! I did miss that line not having the new Array. It has compiled. Thanks again!

Subject: RE: Why do you have parens?

The preferred way to declare an array is to do it literally, like

var myArray = [“one”, “two”, “three”];

See this article for a more in-depth explanation:

http://yuiblog.com/blog/2006/11/13/javascript-we-hardly-new-ya/

Also, there is a good (re-) introduction to JavaScript in Mozilla’s developer section:

To verify your JavaScript, you can use JSLint (pre-compiled off-line versions are available as well):

And finally the final resource on JavaScript:

http://javascript.crockford.com/

Subject: RE: How to: JavaScript onClick button

Subject: RE: How to: JavaScript onClick button

Douglas Crockford, jslint and I disagree. Just because it works, doesn’t mean it is good or correct code.

You don’t have to listen to me, but listening to Douglas Crockford is not all bad.

Subject: RE: How to: JavaScript onClick button

Subject: RE: How to: JavaScript onClick button

Just hope you believe me, that I don’t do it on purpose. :stuck_out_tongue_winking_eye:

Subject: RE: How to: JavaScript onClick button

Any clues on how I do that then? Or how I get rid of this error?

Subject: Fix your var statement

See this

Subject: RE: How to: JavaScript onClick button