0

how do I pass play_ID into the the function toggleSound()?

onclick=\"javascript:var play_ID=$id;toggleSound();\"
<script type=\"text/javascript\">

<script type=\"text/javascript\">
    function toggleSound() {
        audioElem = document.getElementById(\"audio". $row["ID"]."\");
        if (audioElem.paused)
            audioElem.play();
        else
            audioElem.pause();
    }
</script>
4
  • I want the elementById to = play_ID Commented Apr 19, 2016 at 0:22
  • What is play_ID, an input? Can you make a sample? Commented Apr 19, 2016 at 0:39
  • Does play_ID uniquely identify the element that's been clicked? If so you can call toggleSound(this) and declare the function as toggleSound(audioElem) Commented Apr 19, 2016 at 0:55
  • Why do you have backslash before some of the quotes? Is this part of a PHP echo statement? Commented Apr 19, 2016 at 2:09

1 Answer 1

2

If I understand you question correctly, you want to pass the $Id variable into your function?

onclick=\"javascript:toggleSound($id);\"

<script type=\"text/javascript\">

<script type=\"text/javascript\">


 function toggleSound(inVar) {
    //inVar is equal to the variable you want to pass into the function.

        audioElem = document.getElementById(inVar);
        if (audioElem.paused)
            audioElem.play();
        else
            audioElem.pause();
    }
</script>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.