Solved

Dynamic toggle with php

Posted on 2014-11-28
2
160 Views
Last Modified: 2014-11-28
The toggle here is not working...

<p><?php
                  $result = mysqli_query($con,"SELECT * FROM table WHERE qid=".$qid." ORDER BY RAND()");
                  while($row = mysqli_fetch_array($result)) {
                        if ($row['otxm']!=NULL){
                        echo "<span class='radioitem'>";
                        echo "<input type='radio' name='q".$_SESSION["nextPage"]."' value='".$row['scaleValue']."' onclick='toggleDisplay('toggle".$row['scaleValue']."');'>";
                        echo $row['scaleText']."<span id='toggle".$row['scaleValue']."' style='display:none;'>".$row['otxm']."<input type='text' name='otext".$row['scaleValue']."' /></span></span><br>";
                        }
                        else {
                        echo "<span class='radioitem'><input type='radio' name='q".$_SESSION["nextPage"]."' value='".$row['scaleValue']."'>".$row['scaleText']."</span><br>";
                        }
                  }
                  ?></p>
                  
                  
<script type="text/javascript">
<!--
    function toggleDisplay(id) {
            document.getElementById(id).style.visibility = "visible";
            if(document.getElementById(id).style.display == "none" ) {
                  document.getElementById(id).style.display = "";
            }
            else {
                  document.getElementById(id).style.display = "none";
            }
      }
//-->
</script>

I guess the problem is in onclick='toggleDisplay('toggle".$row['scaleValue']."');'
combining all these single/double  quotation marks.
Any Ideas?
0
Comment
Question by:arielbf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
vr6r earned 500 total points
ID: 40470153
Yeah the single quote is cutting your function call short... try changing your radio element to escape the quotes around the string paramater in your onclick call like this:

echo "<input type='radio' name='q".$_SESSION["nextPage"]."' value='".$row['scaleValue']."' onclick='toggleDisplay(\"toggle".$row['scaleValue']."\");'>";

Open in new window

0
 

Author Closing Comment

by:arielbf
ID: 40470160
It is working now, Thank you
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question