I am currenlty working with jquery ui tabs(which works only with next/previous buttons) and a textarea. I have developed an ajax/js function that will auto submit the value stored in the text area and php echo the result in tab#2. But I am currently want to change the method from auto submitting the form to submit when the user clicks the Next button to adavance to the next. How can I submit the value inside a text field when clicking the next button in a jquery ui tabs? Here is my EXAMPLE with autosubmit
PREVIOUS/NEXT
<script>
$(function() {
var $tabs = $('#tabs').tabs({
disabled: [0, 1] });
$(".ui-tabs-panel").each(function(i) {
var totalSize = $(".ui-tabs-panel").size() - 1;
if (i != totalSize) {
next = i + 2;
$(this).append("<a href='#' class='next-tab mover' rel='" + next + "'>Next Page »</a>");
}
if (i != 0) {
prev = i;
$(this).append("<a href='#' class='prev-tab mover' rel='" + prev + "'>« Prev Page</a>");
}
});
$('.next-tab, .prev-tab').click(function() {
var tabIndex = $(this).attr("rel");
$tabs.tabs('enable', tabIndex)
.tabs('select', tabIndex)
.tabs("option","disabled", [0, 1]);
return false;
});
});
HTML/PHP
<?
if (isset($_POST['wmdVal'])){
$wmdVal = $_POST['wmdVal'];
echo ('<div id="wmd_result"><span id="resultval"><h2>PHP Echo result:</h2>'.$wmdVal.'</span></div>');
}
?>
<textarea id="wmd-input" name="wmd-input"></textarea>
<input type="hidden" id="myhidden" name="myhidden" value="<? $wmdVal ?>">
Remember on which tab you are (
currentTab). If a tab is selected, check if the first tab is leaving; if yes send the ajax request with the current preview html; no success handler is needed, we don’t need any client changes. If the next tab is shown, reset thecurrentTabindex. On server side (php) you can e.g. save the data to the database but doesn’t need any result.=== UPDATE ===
If you really want to see a result temporarily for testing, add the success handler again to the ajax parameters:
And append the result
divagain to the end of first tab: