普通网友 2016-11-24 15:29
浏览 123

Html表单提交:可以将表单数据提交到多个目标吗?

I am creating a quiz application which contains two files:

question.php and process.php

In question.php, the user enters his answer in a textbox and clicks a submit button which, by means of a form, has the input he provides processed in a process.php file.
After processing the input, the process.php file redirects the user to a new question.

Now the problem is that before redirecting the user to a new question I want the textbox to glow red if his answer is incorrect and green if correct.
However this obviously needs to be done in the javascript code of the question.php file.

Since the user's input has been sent to the process.php file, I doubt that there is any way of referencing $_POST['answer'] in my question.php's javascript.

In question.php I have the form:

<form method="post" action="process.php">

In question.php I wish to alter the background color of the textbox according to the user's answer. This code is obviously wrong, but it should give you an idea of what I have in mind.

if(<?php echo $_POST['answer']; ?p> != correctAnswer)
document.getElementById('blankSpace').background-colour = red;

The only solution that I can think of is to have the form data submitted to both files. Is this possible?

  • 写回答

1条回答 默认 最新

  • duandong2562 2016-11-24 15:34
    关注

    you will do an ajax call to process.php and based on what process.php returns you do the glow and do a

    window.location.assign('question.php')

    that should do the magic

    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站