单击取消按钮显示另一个文本字段的值

时间:2015-12-23 10:43:22

标签: javascript php magento

我们正在使用magento marketplace多供应商网站。

我们为供应商提供了一个更新前端产品详细信息的选项。

我们正在使用此代码更新价格。工作正常。

PHTML

<input class="ama1" type = "text" id = "price_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name= "price[]" value = "<?php echo $products->getPrice(); ?>" style = ""/>

<input type="hidden" name="curr_<?php echo $products->getId(); ?>" id="curr_<?php echo $products->getId(); ?>" value="<?php echo $products->getPrice(); ?>" />

<p id="updatedprice_<?php echo $products->getId(); ?>" style = "display:none;color:red; position:relative; top:16px;">Updated</p>
<br/>

<button id="price_update_button_<?php echo $products->getId(); ?>" class="update" onclick="updateFieldPrice('<?php echo $products->getId(); ?>'); return false;" >
<span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
</button>

<button id="price_reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideResetPrice('<?php echo $products->getId(); ?>','<?php echo $products->getPrice(); ?>'); return false;">
<span><span><?php echo $helper->__('Cancel') ?></span></span>
</button>

JS

<script>

function hideResetPrice(product_id,priceold) { 

var qtyId='#price_'+ product_id; 
var currprice='#curr_'+ product_id; 
var editLink="#price_edit_link_"+ product_id; 
var updateButton="#price_update_button_"+ product_id; 
var valueprice="#valueprice_"+ product_id; 
var resetButton="#price_reset_button_"+ product_id; 


$wk_jq(valueprice).show(); 
$wk_jq(qtyId).val( $wk_jq(currprice).val()); 
$wk_jq(editLink).show(); 

}



function showFieldPrice(product_id)
        {

            var qtyId='#price_'+ product_id;

            var editLink="#price_edit_link_"+ product_id;
            var valueprice="#valueprice_"+ product_id;
            var updateButton="#price_update_button_"+ product_id;
            var resetButton="#price_reset_button_"+ product_id;

            $wk_jq(qtyId).show();
            $wk_jq(valueprice).hide();

            $wk_jq(editLink).hide();
            $wk_jq(updateButton).show();
            $wk_jq(updateButton).prop('disabled', false);//just in case
            $wk_jq(resetButton).show();

            return false;


        }


function updateFieldPrice(product_id) 
{ 
var priceId = '#price_'+ product_id; 
var currprice='#curr_'+ product_id; 
var updatedqty = '#updatedprice_'+ product_id; 
var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateFieldPrice/')?>'; 
$price = $wk_jq(priceId).val(); 
$wk_jq(currprice).val($price); 
new Ajax.Request(url, { 
method: 'post', 
parameters: {id: product_id, price: $price}, 
onComplete: function (transport) { 
//alert(transport.responseText); 

jQuery(updatedqty).show().delay(2000).fadeOut(); 

} 
}); 
}

我们使用以下代码以获得特价。 最初我们会修改价格值。比一次我们以特价进入一些数字,如果我们点击特价的取消按钮,它显示以前更新的价值&#34;价格&#34; 不是特价。

PHTML

<input class="ama1" type = "text" id = "specialprice_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "specialprice[]" value = "<?php echo $products->getSpecialPrice(); ?>" style = ""/>

<p id="updatedspecialprice_<?php echo $products->getId(); ?>" style = "display:none;color:red; position:relative; top:16px;">Updated</p> 
<br/> 

<button id="specialprice_update_button_<?php echo $products->getId(); ?>" class="update" onclick="updateFieldSpecialPrice('<?php echo $products->getId(); ?>'); return false;"  >
<span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
</button>
<button id="specialprice_reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideResetSpecialPrice('<?php echo $products->getId(); ?>'); return false;" >


<span><span><?php echo $helper->__('Cancel') ?></span></span>
</button>                                                       

</span>

JS

 function hideResetSpecialPrice(product_id,priceold) {

                var qtyId='#specialprice_'+ product_id;
                var currspecialprice='#curr_'+ product_id;
                var editLink="#specialprice_edit_link_"+ product_id;
                var updateButton="#specialprice_update_button_"+ product_id;
                var valuespecialprice="#valuespecialprice_"+ product_id;
                var resetButton="#specialprice_reset_button_"+ product_id;
                $wk_jq(valuespecialprice).show(); 
                $wk_jq(qtyId).val( $wk_jq(currspecialprice).val()); 
                $wk_jq(editLink).show(); 




            }

    function showFieldSpecialPrice(product_id)
            {

                var qtyId='#specialprice_'+ product_id;

                var editLink="#specialprice_edit_link_"+ product_id;
                var valueprice="#valuespecialprice_"+ product_id;
                var updateButton="#specialprice_update_button_"+ product_id;
                var resetButton="#specialprice_reset_button_"+ product_id;

                $wk_jq(qtyId).show();
                $wk_jq(valueprice).hide();

                $wk_jq(editLink).hide();
                $wk_jq(updateButton).show();
                $wk_jq(updateButton).prop('disabled', false);//just in case
                $wk_jq(resetButton).show();

                return false;

           }



    function updateFieldSpecialPrice(product_id) 
    { 
    var priceId = '#specialprice_'+ product_id; 
    var updatedqty = '#updatedspecialprice_'+ product_id; 
    var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateFieldSpecialPrice/')?>'; 
    $price = $wk_jq(priceId).val(); 
    new Ajax.Request(url, { 
    method: 'post', 
    parameters: {id: product_id, price: $price}, 
    onComplete: function (transport) { 
    //alert(transport.responseText); 
    jQuery(updatedqty).show().delay(2000).fadeOut(); 
    } 
    }); 
    }

本地代码

<?php $attribute = $products->getResource()->getAttribute('local');?>
<?php if($attribute):?>
<?php $attribute_value = $attribute ->getFrontend()->getValue($products); ?>

<input class="ama1" type = "text" id = "local_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name= "price[]" value = "<?php echo $attribute_value; ?>" style = ""/>
<?php endif; ?>


<input type="hidden" name="curr_<?php echo $products->getId(); ?>" id="curr_<?php echo $products->getId(); ?>" value="<?php echo $products->getLocal(); ?>" />  

<p id="updatedlocal_<?php echo $products->getId(); ?>" style = "display:none;color:red; position:relative; top:16px;">Updated</p>
<br/>
<button id="local_update_button_<?php echo $products->getId(); ?>" class="update" onclick="updateFieldLocal('<?php echo $products->getId(); ?>'); return false;" >
<span><span style="font-size:12px;"><?php echo $helper->__('Update') ?></span></span>
</button>

<button id="local_reset_button_<?php echo $products->getId(); ?>" type="reset" class="cancel" onclick="hideResetLocal('<?php echo $products->getId(); ?>','<?php echo $products->getPrice(); ?>'); return false;">
<span><span><?php echo $helper->__('Cancel') ?></span></span>
</button>
</span>

JS

function hideResetLocal(product_id,localold) { 

var qtyId='#local_'+ product_id; 
var currlocal='#curr_'+ product_id; 
var editLink="#local_edit_link_"+ product_id; 
var updateButton="#local_update_button_"+ product_id; 
var valuelocal="#valuelocal_"+ product_id; 
var resetButton="#local_reset_button_"+ product_id; 


$wk_jq(valuelocal).show(); 
$wk_jq(qtyId).val( $wk_jq(currlocal).val()); 
$wk_jq(editLink).show(); 

}



function showFieldLocal(product_id)
        {

            var qtyId='#local_'+ product_id;

            var editLink="#local_edit_link_"+ product_id;
            var valuelocal="#valuelocal_"+ product_id;
            var updateButton="#local_update_button_"+ product_id;
            var resetButton="#local_reset_button_"+ product_id;

            $wk_jq(qtyId).show();
            $wk_jq(valuelocal).hide();

            $wk_jq(editLink).hide();
            $wk_jq(updateButton).show();
            $wk_jq(updateButton).prop('disabled', false);//just in case
            $wk_jq(resetButton).show();

            return false;


        }




function updateFieldLocal(product_id) 
{ 
var localId = '#local_'+ product_id; 
var currlocal='#curr_'+ product_id; 
var updatedqty = '#updatedlocal_'+ product_id; 
var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateFieldLocal/')?>'; 
$local = $wk_jq(localId).val(); 
$wk_jq(currlocal).val($local); 
new Ajax.Request(url, { 
method: 'post', 

parameters: {id: product_id, local: $local}, 
//parameters: {id: product_id, local: $local}, 
onComplete: function (transport) { 
//alert(transport.responseText); 

jQuery(updatedqty).show().delay(2000).fadeOut(); 

} 
}); 
}

1 个答案:

答案 0 :(得分:1)

将这个隐藏的文件添加为特价

<input type="hidden" name="specialcurr_<?php echo $products->getId(); ?>" id="specialcurr_<?php echo $products->getId(); ?>" value="<?php echo $products->getSpecialPrice(); ?>" />

更新js

function hideResetSpecialPrice(product_id,priceold) {

                var qtyId='#specialprice_'+ product_id;
                var currspecialprice='#specialcurr_'+ product_id;
                var editLink="#specialprice_edit_link_"+ product_id;
                var updateButton="#specialprice_update_button_"+ product_id;
                var valuespecialprice="#valuespecialprice_"+ product_id;
                var resetButton="#specialprice_reset_button_"+ product_id;
                $wk_jq(valuespecialprice).show(); 
                $wk_jq(qtyId).val( $wk_jq(currspecialprice).val()); 
                $wk_jq(editLink).show(); 




            }

    function showFieldSpecialPrice(product_id)
            {

                var qtyId='#specialprice_'+ product_id;

                var editLink="#specialprice_edit_link_"+ product_id;
                var valueprice="#valuespecialprice_"+ product_id;
                var updateButton="#specialprice_update_button_"+ product_id;
                var resetButton="#specialprice_reset_button_"+ product_id;

                $wk_jq(qtyId).show();
                $wk_jq(valueprice).hide();

                $wk_jq(editLink).hide();
                $wk_jq(updateButton).show();
                $wk_jq(updateButton).prop('disabled', false);//just in case
                $wk_jq(resetButton).show();

                return false;

           }



    function updateFieldSpecialPrice(product_id) 
    { 
    var priceId = '#specialprice_'+ product_id; 
    var currspecialprice='#specialcurr_'+ product_id;
    var updatedqty = '#updatedspecialprice_'+ product_id; 
    var url ='<?php echo Mage::getUrl('marketplace/marketplaceaccount/updateFieldSpecialPrice/')?>'; 
    $price = $wk_jq(priceId).val();
    $wk_jq(currspecialprice).val($price); 
    new Ajax.Request(url, { 
    method: 'post', 
    parameters: {id: product_id, price: $price}, 
    onComplete: function (transport) { 
    //alert(transport.responseText); 
    jQuery(updatedqty).show().delay(2000).fadeOut(); 
    } 
    }); 
    }