duankaolei2921 2017-01-05 18:56
浏览 30
已采纳

如何在php中回显javascript值

I am trying to print a value in PHP which is stored in JS variable.

 document.getElementById("geo").innerHTML = '' + response;

I got the response in id geo

I could able to print through div

e.g <div id ="geo"></div>

I have a input tag I know I can use it as id ="geo" but i want to use it in value for example

<input id= "geocompleat" type="text" value="<?php $geo?>" >

Is there any way to get above JS value in to $geo?

EDIT:

geocompleat is used to get google geo places. i have input tag where i want to use geocompleate and geo location.

my webpage is detect the browser location and if we want to change the location then geocompleat will help to change the location. i tried below but its not working

<input id="geocompleat geo" type="text" name ="location">

so i am trying to to display the geo location in a value="" with php like value= ""

  • 写回答

1条回答 默认 最新

  • dongyinzhi4689 2017-01-05 19:30
    关注

    If you want to set the "response" content to the input, you can do it with javascript so you don't need to use php:

    document.getElementById('your_input_id').value = response;
    

    if you want to send your javascript data, you must make a AJAX GET/POST request.


    Btw. you cannot use multiple values in html id attribute like this :

    You can use only one variable :

    <input id="geocompleat" type="text" name="location">
    

    If you want to use multiple values, use the "class" attribute :

    <input class="geocompleat geo" type="text" name="location">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行