简体   繁体   中英

Unable to get the value of textbox using ajax in a function in php

I have a text box of weight where user will enter weight with button. HTML:

<tr>
    <td>
        <?php echo "Weight:"; ?>
    </td>
    <td>
        <span class='help'><input type="text" value="0" id="ovrdWeight" name="ovrdWeight" size="12" />lb.&nbsp;Enter amount greater than zero to override package weight.</span>
    </td>
</tr>
<span id = "ewsLabel"><a id="generate_hxews_label2" class="button"><span><?php echo "Generate Parameters" ?></span></a></span>

Button click code:

$('#generate_hxews_label2').click(function() {
    $.post('index.php?route=sale/order/generateEWSParameters&token=<?php echo $token; ?>&Mailtype=' + $('#category_type').val()  + '&ClassMail=' + $('#classmail').val() + '&labelsize=' +  $('#hxews_labelimgsize').val()+ '&mailpieces_option=' +  $('#hxews_labelpieces').val() + '&order_id=<?php echo $order_id; ?>' + '&ovrdWeight=' +  $('#ovrdWeight').val(),
    {
        token : '<?php echo $token; ?>',
        order_id : '<?php echo $order_id; ?>'
    },

so on..

Than in my function i am just printing this variable VIA get method but everytime i get 0 output.

$this->request->get['ovrdWeight'];

I have another dropdown list exactly here its output is accurate but not this textbox.

$('#generate_hxews_label2').click(function() {
      $.post(
      'index.php?route=sale/order/generateEWSParameters&token=<?php echo $token; ?>&Mailtype=' + $('#category_type').val()  + '&ClassMail=' + $('#classmail').val() + '&labelsize=' +  $('#hxews_labelimgsize').val()+ '&mailpieces_option=' +  $('#hxews_labelpieces').val() + '&order_id=<?php echo $order_id; ?>' + '&ovrdWeight=' + $('#ovrdWeight').val(),
      {
      token : '<?php echo $token; ?>',
      order_id : '<?php echo $order_id; ?>'
      },

You define textbox value as 0.You need to remove value attribute from textbox.

<span class='help'><input type="text" value="0" id="ovrdWeight" name="ovrdWeight" size="12" />lb.&nbsp;Enter amount greater than zero to override package weight.</span>

Above element change with the following-

   <span class='help'><input type="text" id="ovrdWeight" name="ovrdWeight" size="12" />lb.&nbsp;Enter amount greater than zero to override package weight.</span>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM