dousuo8400 2014-06-06 16:04
浏览 76

动态获取隐藏字段值而无需提交表单

my query is generating 3 result with three send enquiry button which send the value of there respective hidden field but all the time when i click send enquiry button i show me always the 1st company name in my javascript

here is my php..

  $adcategory=$_GET['category'];
  mysql_connect('localhost','root','');
  mysql_select_db('advertising site');
  $selectquery="select * from business_ads where company_category='$adcategory'";
  $result=mysql_query($selectquery)or die(mysql_error());
  $resultrows=mysql_num_rows($result);
  if($resultrows>=1)
  {
  echo"<p>$resultrows</p>";
  while($row=mysql_fetch_array($result))
  {
  $companyname=$row['company_name'];?>
  <div id="ads">
  <p id="company_name" name="company_name"><?php echo $companyname?></p>
  <input type="hidden" name="hidden_company_name" value="<?php echo        
  $companyname>"id="hidden_name">   
  <input type="hidden" name="hidden_company_name" value="<?php echo $companyname ?    
  >"id="hidden_name">
  <center><input type="button" name="send_enquiry" id="send_enquiry" value="Send    
  Enquiry"       
  onclick="f1();"></center>
  <input type="submit"value="submit" name="submit_enquiry_form">

 </div>
 <?php
 }
 }

and here is my javascript

 function f1()
 {
 var comp_name=document.getElementById('hidden_name').value;
 var elements=comp_name;
 document.write(elements);
 }
  • 写回答

1条回答 默认 最新

  • duanjiwei1283 2014-06-06 16:07
    关注

    Both these show there is no space between your closing quote and the id

    <input type="hidden" name="hidden_company_name" value="<?php echo        
    $companyname>"id="hidden_name">   
    <input type="hidden" name="hidden_company_name" value="<?php echo $companyname ?    
    >"id="hidden_name">
    

    Also it is bad coding to have more than one element with the same ID. As you will never end up with the proper element when you try to reference it by ID.

    If this is just going to be a hidden value that is not changed by javascript then simply doing this will provide the value into a js var.

    <script type="text/javascript">
    var valueIwant="<?php echo $companyname; ?>";
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据