Javascript Subroutine Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PVACC
    New Member
    • Oct 2008
    • 4

    Javascript Subroutine Problem

    The following line of script code works correctly:

    Code:
    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.

    Code:
    <sub mySub(x)
    {
    myImg.src=\'../Audio Streaming/'+x);
    }
    I replaced the above line of code with :

    Code:
    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
    Last edited by gits; Oct 27 '08, 10:45 AM. Reason: added code tags
  • zaphod42
    New Member
    • Oct 2008
    • 55

    #2
    I can't see where myPhoto is defined in the scope of what you're doing....do you have any more javascript on the page?

    Comment

    • PVACC
      New Member
      • Oct 2008
      • 4

      #3
      Originally posted by zaphod42
      I can't see where myPhoto is defined in the scope of what you're doing....do you have any more javascript on the page?
      Yes I do have other javascript. The major portion is as follows:

      Code:
      function w(s)
      {
      	document.writeln(s);
      }
      var previousSpeaker="", previousSeries="";					// initialize variables to empty string
      for(var i=0; i<parent.audio_info.length; i++)  				// loop through all listed audios
      {
      	var sermon=parent.audio_info[i];        				// get next audio as an array of 5 strings
      	var mySwf=sermon[0];	// Streaming Audio "swf" file
      	var mySpeaker=sermon[1];	// Speaker's Name
      	var myPhoto=sermon[2]; 	// Speaker's "jpg" photo
      	var mySeries=sermon[3]; 	// Sermon Series Title
      	var myTitle=sermon[4];	// Sermon Title
      
      	if(mySpeaker!=previousSpeaker || mySeries!=previousSeries)  // new speaker or series?
      	{
      		w('<br><span style="font-family: Swis721 Blk BT">');
      		w('<font size="4" color="#333399">');
      		w(mySpeaker);
      		w('</font></span>');
      		w(' : '+mySeries);
      		w('<br>');
      	}
      	w('<input type=radio name=rad onclick="mySub(myPhoto)">');
      	w(myTitle);
      	w('<br>');
      	previousSpeaker=mySpeaker; 
      	previousSeries=mySeries;
      }
      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.
      Last edited by acoder; Oct 27 '08, 07:41 AM. Reason: Added [code] tags

      Comment

      Working...