Hide Text and Display Message on Button Click – JavaScript Guide

javascriptout-of-stockproduct-viewshipping

please visit link1 , you can see there is option to find shipping is available or not for particular zip code : image1

enter image description here

what i want is , once we enter " 110001" in textfield, click on "check" button, it should show as below image 2 :

enter image description here

means 1)"Available with 14 sellers" text + 2)"entered zip code" + 3)"change" button.

Now i got solution for 1) & @2) , i need to to display "change" button.

once we click on "change" button, again it should show as in image 1.

we are using custom module for displaying shipping charges in Product View page. you can download using Magento Display shipping estimation block

Form.phtml

app/design/frontend/default/default/template/webdevlopers/productpageshipping/estimate/form.phtml

<?php if ($this->isFieldVisible('postcode')): ?> 
<li class="item"> 

<label for="search"<?php if ($this->isFieldRequired('postcode')):?> class="required" <?php endif;?>><?php if ($this->isFieldRequired('postcode')):?><em>*</em><?php endif;?><?php echo Mage::helper('webdevlopers_productpageshipping')->__('') ?></label> 
<div class="search"> 

<input placeholder="Enter your PIN Code" class="input-text validate-postcode<?php if ($this->isFieldRequired('postcode')):?>
required-entry<?php endif;?>" type="text" id="estimate_postcode" name="estimate[postcode]" 
value="<?php echo $this->htmlEscape($this->getFieldValue('postcode')) ?>" onkeydown="if (event.keyCode == 13) { return false;}" /> 
</div> 
</li> 
<?php endif; ?> 

Script

<script type="text/javascript"> 
var $ = jQuery.noConflict(); 
( function($) { 
$(document).ready(function(){ 
$('#estimate_postcode').keydown(function(e){ 

var items = $$(['.shipping-estimation-form input', 
'.shipping-estimation-form select', 
'#product_addtocart_form input', 
'#product_addtocart_form select']); 
var estimationUrl = '<?php echo $this->jsQuoteEscape($this->getEstimateUrl());?>'; 
var parameters = Form.serializeElements(items, true); 
console.log("zipcode onkeypress worked"); 
if (!e) e = window.event; 
var keyCode = e.keyCode || e.which; 
if (keyCode == '13'){ 
//disable default enter action 
e.preventDefault(); 
console.log("Enter button was pressed"); 
$('#shipping-estimate-loading-message').show(); 
$('#shipping-estimate-results').hide(); 

new Ajax.Updater('shipping-estimate-results', estimationUrl, { 
parameters: parameters, 
onComplete: function() { 
console.log("ajax updater worked"); 
$('#shipping-estimate-loading-message').hide(); 
$('#shipping-estimate-results').show(); 
$('#unique_id').hide(); 
//$('unique_id').hide(); 
$('estimate_postcode').val()
} 
}); 
}; 
}); 
}); 
} ) ( jQuery ); 

function estimateProductShipping() 
{ 

var estimationUrl = '<?php echo $this->jsQuoteEscape($this->getEstimateUrl());?>'; 
var items = $$(['.shipping-estimation-form input', 
'.shipping-estimation-form select', 
'#product_addtocart_form input', 
'#product_addtocart_form select']); 

var validationResult = true; 

// Check the valid input 
if (!items.map(Validation.validate).all()) { 
return; 
} 

var parameters = Form.serializeElements(items, true); 

$('shipping-estimate-loading-message').show(); 
$('shipping-estimate-results').hide(); 


new Ajax.Updater('shipping-estimate-results', estimationUrl, { 
parameters: parameters, 
onComplete: function() { 
console.log("ajax updater worked"); 
$('shipping-estimate-loading-message').hide(); 
$('shipping-estimate-results').show(); 
// $('#unique_id').hide(); 
$('unique_id').hide(); 
$('estimate_postcode').val()
} 
}); 
} 

//]]> 
</script> 

complete code of the file : https://gist.github.com/anonymous/ebe868508b2c21e9c032

result.phtml

app/design/frontend/default/default/template/webdevlopers/productpageshipping/estimate/result.phtml

<p><?php echo "Available with 14 sellers at";?>
<?php  $addressInfo = $this->getRequest()->getPost('estimate',array()); ?>
<?php if(isset($addressInfo['postcode']) && $addressInfo['postcode']):?>
<?php echo ' '.$this->htmlEscape($addressInfo['postcode']); ?>
<?php endif;?>
</p>

Edit

Once i used below answer , than i got my solution for displaying message.

Now i need to display change button after message.

Best Answer

Add bellow code

result.phtml

<p style="font-size:20px;"><?php echo "Available with 14 sellers at";?>
<?php  $addressInfo = $this->getRequest()->getPost('estimate',array()); ?>
<?php if(isset($addressInfo['postcode']) && $addressInfo['postcode']):?>
    <?php echo ' '.$this->htmlEscape($addressInfo['postcode']); ?>
<?php endif;?>
    <a style="text-decoration: underline" href="javascript:void(0)" onclick="changeEstimate();"><?php echo $this->__('change')?></a>
</p>

Script:

app/design/frontend/default/default/template/webdevlopers/productpageshipping/estimate/form.phtml

<script type="text/javascript"> 
var $ = jQuery.noConflict(); 
( function($) { 
$(document).ready(function(){ 
$('#estimate_postcode').keydown(function(e){ 

var items = $$(['.shipping-estimation-form input', 
'.shipping-estimation-form select', 
'#product_addtocart_form input', 
'#product_addtocart_form select']); 
var estimationUrl = '<?php echo $this->jsQuoteEscape($this->getEstimateUrl());?>'; 
var parameters = Form.serializeElements(items, true); 
console.log("zipcode onkeypress worked"); 
if (!e) e = window.event; 
var keyCode = e.keyCode || e.which; 
if (keyCode == '13'){ 
//disable default enter action 
e.preventDefault(); 
console.log("Enter button was pressed"); 
$('#shipping-estimate-loading-message').show(); 
$('#shipping-estimate-results').hide(); 

new Ajax.Updater('shipping-estimate-results', estimationUrl, { 
parameters: parameters, 
onComplete: function() { 
console.log("ajax updater worked"); 
$('#shipping-estimate-loading-message').hide(); 
$('#shipping-estimate-results').show(); 
$('#unique_id').hide(); 
//$('unique_id').hide(); 
$('estimate_postcode').val()
} 
}); 
}; 
}); 
}); 
} ) ( jQuery ); 

function estimateProductShipping() 
{ 

var estimationUrl = '<?php echo $this->jsQuoteEscape($this->getEstimateUrl());?>'; 
var items = $$(['.shipping-estimation-form input', 
'.shipping-estimation-form select', 
'#product_addtocart_form input', 
'#product_addtocart_form select']); 

var validationResult = true; 

// Check the valid input 
if (!items.map(Validation.validate).all()) { 
return; 
} 

var parameters = Form.serializeElements(items, true); 

$('shipping-estimate-loading-message').show(); 
$('shipping-estimate-results').hide(); 


new Ajax.Updater('shipping-estimate-results', estimationUrl, { 
parameters: parameters, 
onComplete: function() { 
console.log("ajax updater worked"); 
$('shipping-estimate-loading-message').hide(); 
$('shipping-estimate-results').show(); 
// $('#unique_id').hide(); 
$('unique_id').hide(); 
$('estimate_postcode').val()
} 
}); 
}

function changeEstimate(){
    $('unique_id').show();
    $('shipping-estimate-results').hide();
}

/* 

Event.observe('delivery-pincode-change', 'click', function(event){
$('unique_id').show();
$('shipping-estimate-results').hide();               
$('delivery-html').hide();
});

*/


/* 

$(document).ready(function(){ 
$('check1234').on('click', function(){ 
$('#unique_id').hide(); 
$('#shipping-estimate-results').show(); 
}); 
}); 

*/ 
//]]> 
</script>
Related Topic