By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,839 Members | 1,616 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,839 IT Pros & Developers. It's quick & easy.

Javascript Subroutine Problem

P: 4
The following line of script code works correctly:

Expand|Select|Wrap|Line Numbers
  1. w('<input type=radio name=rad onclick="myImg.src=\'../Audio Streaming/'+myPhoto+'\';">');
When onclick is executed, the variable "myPhoto" is correctly loaded as the source for "myImg" which is then displayed.

I need to accomplish several tasks when "onclick" is executed and I am trying to setup a subroutine "mySub" to perform the various tasks. I created a subroutine as follows, located in the <body> of the html routine.

Expand|Select|Wrap|Line Numbers
  1. <sub mySub(x)
  2. {
  3. myImg.src=\'../Audio Streaming/'+x);
  4. }
I replaced the above line of code with :

Expand|Select|Wrap|Line Numbers
  1. w('<input type=radio name=rad onclick="mySub(myPhoto)">');
to pass the parameter "myPhoto" to the subroutine, but I keep getting the error message "Object Expected".

Can anyone tell me what I am doing wrong?

Thanks - Patrick Russell
Oct 26 '08 #1
Share this Question
Share on Google+
2 Replies

P: 55
I can't see where myPhoto is defined in the scope of what you're you have any more javascript on the page?
Oct 26 '08 #2

P: 4
I can't see where myPhoto is defined in the scope of what you're you have any more javascript on the page?
Yes I do have other javascript. The major portion is as follows:

Expand|Select|Wrap|Line Numbers
  1. function w(s)
  2. {
  3.     document.writeln(s);
  4. }
  5. var previousSpeaker="", previousSeries="";                    // initialize variables to empty string
  6. for(var i=0; i<parent.audio_info.length; i++)                  // loop through all listed audios
  7. {
  8.     var sermon=parent.audio_info[i];                        // get next audio as an array of 5 strings
  9.     var mySwf=sermon[0];    // Streaming Audio "swf" file
  10.     var mySpeaker=sermon[1];    // Speaker's Name
  11.     var myPhoto=sermon[2];     // Speaker's "jpg" photo
  12.     var mySeries=sermon[3];     // Sermon Series Title
  13.     var myTitle=sermon[4];    // Sermon Title
  15.     if(mySpeaker!=previousSpeaker || mySeries!=previousSeries)  // new speaker or series?
  16.     {
  17.         w('<br><span style="font-family: Swis721 Blk BT">');
  18.         w('<font size="4" color="#333399">');
  19.         w(mySpeaker);
  20.         w('</font></span>');
  21.         w(' : '+mySeries);
  22.         w('<br>');
  23.     }
  24.     w('<input type=radio name=rad onclick="mySub(myPhoto)">');
  25.     w(myTitle);
  26.     w('<br>');
  27.     previousSpeaker=mySpeaker; 
  28.     previousSeries=mySeries;
  29. }
Code continues ... Basically, the user selects a radio button from a list, from which the correct sermon tiltle and audio flash file are extracted and used.
Oct 27 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.