JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2057
Number of posts: 5155

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How to play music by clicking link Posted by jeffy_khor on 28 Mar 2004 at 9:05 PM
<bgsound id = snd1>
<script language=javascript>
	snd1.src = "song.mid"

	function playx(){
		//alert("Next song")
		snd1.src = "xMas.mid"
		return true;
	}

</script>

<a href="" onmousedown="playx(); return false;">Next song</a>


how to click the link and change the music to the next song. The above code don't work.

Thank you.
Report
Re: How to play music by clicking link Posted by GideonOmega on 28 Mar 2004 at 9:25 PM
:
: <bgsound id = snd1>
: <script language=javascript>
: 	snd1.src = "song.mid"
: 
: 	function playx(){
: 		//alert("Next song")
: 		snd1.src = "xMas.mid"
: 		return true;
: 	}
: 
: </script>
: 
: <a href="" onmousedown="playx(); return false;">Next song</a>
: 

:
: how to click the link and change the music to the next song. The above code don't work.
:
: Thank you.
:
try
<a href="playx()"......

C:\Dos
C:\Dos Run
Run Dos Run


Report
Re: How to play music by clicking link Posted by zibadian on 28 Mar 2004 at 10:58 PM
: :
: : <bgsound id = snd1>
: : <script language=javascript>
: : 	snd1.src = "song.mid"
: : 
: : 	function playx(){
: : 		//alert("Next song")
: : 		snd1.src = "xMas.mid"
: : 		return true;
: : 	}
: : 
: : </script>
: : 
: : <a href="" onmousedown="playx(); return false;">Next song</a>
: : 

: :
: : how to click the link and change the music to the next song. The above code don't work.
: :
: : Thank you.
: :
: try
: <a href="playx()"......
:
: C:\Dos
: C:\Dos Run
: Run Dos Run
:

:
:
The correct code to run a javascript function using the anchor is:
  <a href="javascript:playx()">

The code above assumes that playx() is a link to another page. You can also use the onclick() event.
Report
Re: How to play music by clicking link Posted by lillu on 29 Mar 2004 at 6:50 AM
To call a function for which you do not expect a return value, do this:

<a href="javascript:void(playx())">Click Me</a>


: : : <bgsound id = snd1>
: : : <script language=javascript>
: : : 	snd1.src = "song.mid"
: : : 
: : : 	function playx(){
: : : 		//alert("Next song")
: : : 		snd1.src = "xMas.mid"
: : : 		return true;
: : : 	}
: : : 
: : : </script>
: : : 
: : : <a href="" onmousedown="playx(); return false;">Next song</a>
: : : 

: : :
: : : how to click the link and change the music to the next song. The above code don't work.
: : :
: : : Thank you.
: : :
: : try
: : <a href="playx()"......
: :
: : C:\Dos
: : C:\Dos Run
: : Run Dos Run
: :

: :
: :
: The correct code to run a javascript function using the anchor is:
:
:   <a href="javascript:playx()">
: 

: The code above assumes that playx() is a link to another page. You can also use the onclick() event.


To err is human, but to really foul things up requires a computer. (Farmers Almanac)

Report
Re: How to play music by clicking link Posted by jeffy_khor on 29 Mar 2004 at 9:26 PM
<bgsound id = snd1>
<script language=javascript>
	snd1.src = "song.mid"

	function playx(){
		//alert("Next song")
		snd1.src = "xMas.mid"
		return false;
		//return true;
	}

</script>

<a href="javascript:void(playx())">Next song</a>
<a href="" onclick="return playx()">Again</a>
<a href="" onmousedown="return playx()">Why this link don't work</a>


Why the 3rd link don't work but the second work.
Thank you for answer.

: To call a function for which you do not expect a return value, do this:
:
: <a href="javascript:void(playx())">Click Me</a>
:
:
:
: : : : <bgsound id = snd1>
: : : : <script language=javascript>
: : : : 	snd1.src = "song.mid"
: : : : 
: : : : 	function playx(){
: : : : 		//alert("Next song")
: : : : 		snd1.src = "xMas.mid"
: : : : 		return true;
: : : : 	}
: : : : 
: : : : </script>
: : : : 
: : : : <a href="" onmousedown="playx(); return false;">Next song</a>
: : : : 

: : : :
: : : : how to click the link and change the music to the next song. The above code don't work.
: : : :
: : : : Thank you.
: : : :
: : : try
: : : <a href="playx()"......
: : :
: : : C:\Dos
: : : C:\Dos Run
: : : Run Dos Run
: : :

: : :
: : :
: : The correct code to run a javascript function using the anchor is:
: :
: :   <a href="javascript:playx()">
: : 

: : The code above assumes that playx() is a link to another page. You can also use the onclick() event.
:
:
To err is human, but to really foul things up requires a computer. (Farmers Almanac)
:
:

Report
Re: How to play music by clicking link Posted by Weirdofreak on 30 Mar 2004 at 8:20 AM
I don't know exactly what you mean by working, but I'd assume that the second one plays the music, and the third one sends you to a blank URL. The reason is that when you return a value of false in an event handler, it doesn't do what it normally should. Therefore when you return false a mousedown the link won't change color like normal, whereas returning false a click (which is when you actually get sent to the page) won't send you.
Report
Re: How to play music by clicking link Posted by jeffy_khor on 31 Mar 2004 at 1:11 AM
For working, three link will play a music. But why the third link don't play a music but change to a blank link as the second link can play the music and don't go to other page.

As I am return false to the link, it should stop link to the page and play the music.

Thank you.

: I don't know exactly what you mean by working, but I'd assume that the second one plays the music, and the third one sends you to a blank URL. The reason is that when you return a value of false in an event handler, it doesn't do what it normally should. Therefore when you return false a mousedown the link won't change color like normal, whereas returning false a click (which is when you actually get sent to the page) won't send you.
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.