Solved

Dynamic toggle with php

Posted on 2014-11-28
2
148 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now