doucheng1063 2013-12-12 05:33 采纳率: 100%
浏览 225

如何将数据从可点击的div填充到文本框?

I am trying to populate data from a click-able div container to a text box. All the below code is present in same file "schedule.php".

The jQuery function is:

$(document).ready(function(){
 $("#listItem1").click(function(){
  var selectedAddress = $("#listItem1").attr("value");
  $.post("schedule.php",selectedAddress,function(selectedAddress){
    addressSelect($("#listItem1").attr("value"));
  });

 });
});

The php code is present in the same file:

<?php 
  function addressSelect($selectedAddress) {
$selectedAddress=$_POST['$selectedAddress'];    
//echo $selectedAddress;
    if(isset($selectedAddress)) list($fromName, $fromAddress, $fromCity,     $fromState, $fCountry, $fromZip, $fromPhone) = explode("$$$", $selectedAddress);
  }
?>

I am not able to populate it. I tried to using $.ajax also... but not helping.. what should I do to populate the textboxes at all.

The HTML is like this:

<table CELLSPACING=0 CELLPADDING=1 border=0 width=200>
    <tr><td colspan=4 height=10></td></tr>
    <tr>
      <td width=7></td>
      <td WIDTH=180 height=35><b>Name</b><font size="-1" color="#FF0000">*</font></td>
      <td colspan=2 WIDTH=220>
        <input NAME="fromName" TYPE="text" id="fromName" placeholder="Sender's Name" style="width:150px;" value="<?php echo $fromName;?>" MAXLENGTH="35" autofocus onBlur="ValidateName(fromName)">
        <span class="error">  <?php echo $fromNameErr;?></span>
      </td>
    </tr>    

    <tr>
      <td></td>
      <td height=35><b>Address</b><font size="-1" color="#FF0000">*</font></td>
      <td>
      <TEXTAREA NAME="fromAddress" COLS=30 ROWS=3 id="fromAddress" placeholder="Sender's Address" style="width:200px; height:130px; font-size:13px; font-family:Arial,sans-serif" onBlur="ValidateAddress(fromAddress)"></TEXTAREA>
      <span class="error">  <?php echo $fromAddressErr;?></span>
      </td>      
      <td rowspan=3 align="center"></td>     
    </tr>

    <tr>
      <td></td>
      <td height=35><b>Landmark</td>
      <td>
      <input NAME="fromLandmark" TYPE="text" id="fromLandmark" placeholder="optional" style="width:150px" value="<?php echo $fromLandmark;?>" MAXLENGTH=45>
      </td>
    </tr>

    <tr>
      <td></td>
      <td height=35><b>City</b><font size="-1" color="#FF0000">*</font></td>
      <td>
      <input NAME="fromCity" TYPE="text" id="fromCity" placeholder="Source City" style="width:150px" value="<?php echo $fromCity;?>" MAXLENGTH=35>
      </td>
    </tr>

    <tr>
      <td></td>
      <td height=35><b>State</b><font size="-1" color="#FF0000">*</font></td>
      <td colspan=2>
      <input NAME="fromState" TYPE="text" id="fromState" placeholder="State of Source City" style="width:150px" value="<?php echo $fromState;?>" MAXLENGTH=25>
      </td>
    </tr>

    <tr>
      <td></td>
      <td height=35><b>Zip</b><font size="-1" color="#FF0000">*</font></td>
      <td colspan=2>
      <input NAME="fromZip" TYPE="text" id="fromZip" placeholder="Pin Code" style="width:90px" value="<?php echo $fromZip;?>" MAXLENGTH=15 onBlur="ValidateZip(fromZip)">
      <span class="error">  <?php echo $fromZipErr;?></span>
      </td>
    </tr>

    <tr>
      <td></td>
      <td height=35><b>Country</b></td>
      <td colspan=2>
      <select NAME="fromCountry" id="fromCountry" disabled="disabled">
      <?php populate_country();?>
      </select></div></td>
      </td>
    </tr>  

    <tr>
      <td></td>
      <td height=35><b>Phone</b><font size="-1" color="#FF0000">*</font></td>
      <td colspan=2>
      <input NAME="fromPhone" TYPE="text" id="fromPhone" placeholder="Sender's Phone no." style="width:150px" value="<?php echo $fromPhone;?>" MAXLENGTH=15 onBlur="ValidatePhone(fromPhone)">
      <span class="error">  <?php echo $fromPhoneErr;?></span>
      </td>
    </tr>

    <tr><td colspan=4 height=10></td></tr>
  </table>
        <?php /*?><td style="border-right:1px solid #b2b2b2; font-size:1px; background-color: #fafafa">&nbsp;</td><?php */?>
    </tr>
    <tr>
        <td width=6 height=6></td>
        <?php /*?><td height=6 style="border-bottom:1px solid #b2b2b2; font-size:1px; background-color: #fafafa">&nbsp;</td><?php */?>
        <td width=6 height=6></td>
    </tr>
  </table><!-- End of From Address container table-->
  • 写回答

2条回答 默认 最新

  • douewei1665 2013-12-12 05:45
    关注

    I think you want to copy the data on the browser and not on the server. You can use the following JQuery code to get it done:

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
    </script>
    <script language="javascript" type="text/javascript"> 
        function copyData(divId, textBoxId) { 
            content = $("#" + divId).html();
            $("#" + textBoxId).val(content); 
        }
    </script> 
    <body>
        <div id="my-div" onclick="copyData('my-div', 'my-text-box');">
            This the data to be copied.
        </div>
        <input type="text" id="my-text-box" name="myTextBox"/>
    </body>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测