tags:

views:

133

answers:

1

how do I capture the submit event in this particular scenario( I am using Kohana):?

controller function (swo/test):

echo "Form succesfully submitted.<br/>";
$min = $_POST['price1'];
$max = $_POST['price2'];
echo "Minimum Value:" . $min . "<br/>";
echo "Maximum Value:" . $max;

$q = new Swo_Model;
$result = $q->searchRange($min, $max);
echo Kohana::debug($result);
$view= new View('template');
$view->slider = new View('slider');
$view->content = new View('advsearch');
$view->content->list = $result;

$view->render(TRUE);

HERE IS MY JQUERY SCRIPT

$(document).ready(function()
{
$('#slider').slider({
    min:0,
    steps: 50,
    max:300,
    range: true,
    change: function(e,ui){
     $("#min").text("$" + ui.values[0]);
     $("#max").text("$" + ui.values[1]);
     $("input[name='price1']").val(ui.values[0]);
     $("input[name='price2']").val(ui.values[1]);
     $("#advance").trigger("submit");
    }
});
});

I have a slider. I slide it to a particular value, then trigger a form submit via jquery. What I want to do is load the output of the testSubmit function to a specific region in my page, without the slider being refreshed. I tried to do it with the submit(function(){}) already but to no avail.

+1  A: 

You need to prevent the event from bubbling up - what is happening is that your function is running, and then the form is still submitting.

A quick solution is

<form ... onsubmit="return myfunction()">

And in myFunction, return false, which will stop the submit being posted. You could even trap errors in your jquery and return true to cause the proper submit if something goes wrong, which means graceful deprecation if there's a problem.

Sohnee
a colleague here at the workplace suggested I use the ajax() function instead. But is there not a way to do this without using the ajax() function?

related questions