Solved

Dynamic toggle with php

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

733 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