-1

In my _value form table 3 input as voltage ,type and length AS show image.r,x,b value came from type table as type select.

enter image description here

Value Submit

  1. page not refresh on submit
  2. on submit temp result=r*length

Again when enter value and submit then show second result in below first one till user do. on clear all result clean. "how we can achieve using javascript append and prepend"

vard
  • 4,057
  • 2
  • 26
  • 46

1 Answers1

1

For your solution, call a javascript function on onClick() of Submit button and add following code:

<?php echo CHtml::submitButton('Submit', array('onClick' => 'js: return submitForm(this);')); ?>
<?php echo CHtml::button('Clear', array('onClick' => 'js: return clearForm(this);')); ?>

<script type="text/javascript" language="Javascript">
  function submitForm(obj) {
    var r = document.getElementById("TestpageForm_r").value;
    var len = document.getElementById("TestpageForm_length").value;
    var result = 0;

    if (r != "" && len != "") {
      result = r * len;      
      var strAppend = '<div class="row"><span>Result: </span><span>' + result + '</span></div>';
      $('#mainDiv').append(strAppend);
    }
    else{
      alert('Please enter value of r and length');
    }
    return false;
  }
  function clearForm(obj) {
    document.getElementById('mainDiv').innerHTML = "";
  }
</script>
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57