Solved

Dynamic toggle with php

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 discusses four methods for overlaying images in a container on a web page
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

744 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

11 Experts available now in Live!

Get 1:1 Help Now