dongshun1884 2014-06-21 01:21
浏览 94

将html表单发布数据传递到不同的文件/网页javascript变量(php)

So I'm trying to pass simple form data from my file ResName.html

<head>
<form action="file:///E:/programs/portAppJavascript.html" method="post">
    Name: <input id = 'name'>
    <br>
    Number of Reservations: <input type="text" id ='resseats' name="resseat">
    <input type='submit' value="Choose Seats">

</form>

</head>`

to my file portAppJavascript.html. I'm just trying to pass the number of reservations to a js variable below.

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

var isClicked = false;
var counter = 0;
var numSeatsBought = <?php $_GET['resseat'] ?>; //window.location.search; //change to get from other     html page
var seatArray = new Array();

function clicked(clicked_id){

////////////////
var links = document.head.getElementsByTagName('link');
for(var link in links){
    if(links.hasOwnProperty(link)){
        var l = links[link];
        if(l.rel === 'canonical'){
          alert(l.href);
    }
}
}

Why is it not passing the number to the javascript variable? How can I fix this? numSeatsBought is the variable that's not receiving the data correctly.

  • 写回答

1条回答 默认 最新

  • douju7765 2014-06-21 01:29
    关注

    There are a few problems here:

    1. Your form uses the POST method, but in the next file you check for a GET variable. You should use $_POST['resseat'] there;
    2. You are posting to a file, not a script on a server like http://localhost/... so there is no web-server involved and your php will not be processed;
    3. The script you are posting to, has the .html extension so the php will probably not be processed even if you fix the second problem.
    评论

报告相同问题?

悬赏问题

  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊