drgbpq5930 2014-11-05 06:32
浏览 115

如何在iframe中获取已检查单选按钮的值

I have here a page with iframe. Inside the iframe, it will display all the questions in multiple choice. The problem is that I don't know how to get all the values of the checked radio buttons inside the iframe. The button is in the parent page (I haven't included it yet).

This is the screen capture of my page (questions.php):

Webpage

This is my iframe code from questions.php:

<div class="question-display test">
     <iframe src="questions/frame.php" height="500px" width="100%">

     </iframe>
</div>

This is my frame.php (displaying all the questions)

<?php
                include('config.php');
                $view_questions=mysql_query("SELECT * FROM questions ORDER BY RAND()");
                $count=mysql_num_rows($view_questions);
                    $i=1;
                    while($row=mysql_fetch_array($view_questions))
                    {

                ?>
        <div class="questions-contents text-size test" style="margin-left: 10px;">
            <p align="justify"><strong><?php echo $i;?>.)</strong> <?php echo $row['QUESTION'];?></p>
        </div>


        <div class="answer-indent" style="margin-left: 40px; margin-bottom: 20px;">    
            <label class="radio">
                <input type="radio" name="<?php echo $row['QUESTION_NO'];?>" value="1" data-toggle="radio">
                <class="color" style="color: gray;"><?php echo $row['ANSWER_1'];?></class="color">
            </label>

            <label class="radio">
                <input type="radio" name="<?php echo $row['QUESTION_NO'];?>" value="2" data-toggle="radio">
                <class="color" style="color: gray;"><?php echo $row['ANSWER_2'];?></class="color">
            </label>
            <label class="radio">
                <input type="radio" name="<?php echo $row['QUESTION_NO'];?>" value="3" data-toggle="radio">
                <class="color" style="color: gray;"><?php echo $row['ANSWER_3'];?></class="color">
            </label>

            <label class="radio">
                <input type="radio" name="<?php echo $row['QUESTION_NO'];?>" value="4" data-toggle="radio">
                <class="color" style="color: gray;"><?php echo $row['ANSWER_4'];?></class="color">
            </label>

            <label class="radio" style="display: none;" >
                <input type="radio" name="<?php echo $row['QUESTION_NO'];?>" value="5" data-toggle="radio" checked>

            </label>
        </div>
            <?php
                    $i++; }
            ?>

Before I make my frame.php inserted to iframe from the questions.php page, I have a php codes for checking the answers of the users (the checked radio buttons).

$questions = mysql_query("SELECT * FROM questions");
while($row=mysql_fetch_assoc($questions)){
    if($_POST[$row['QUESTION_NO']]==$row["ANSWER"])
    {
        $score++;
    } 
    elseif($_POST[$row['QUESTION_NO']]==5)
    {
        $unanswered++;
    }
    else
    {
        $wrong_score++;
    }
}

Please help me, I'm doing this since yesterday but I didn't get it. I don't know how to do it.

  • 写回答

3条回答 默认 最新

  • dt614037527 2014-11-05 06:47
    关注

    You can give id to your iframe and access its elements.

    document.getElementById('frameid').contentWindow.document.getElementById('abc')

    Where abc is your radio button element.

    Then you can do whatever you want to do with element.

    But seriously, you can do the same thing in Div also with proper css.

    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)