A few comments:
You must first add the echoed html from PHP, only then can you access it from jquery using $ ("# resultval")
I will explain - look at your "success" handler
success: function(result) { $('#textarea_result').html( $('#resultval', result).html()); $('#title_result').html( $('#resultval', result).html()); }
The code should be
success: function(result) { $('#textarea_result').html( result); $('#title_result').html( result); }
If at all ... but I don't think that is what you had in mind.
If you want to ask me, do the whole next tab in PHP and do something like $("#tab2").html(result);
Comment No. 2 You have 2 identical identifiers - the result.
Comment No. 3 - You submit "textarea" and "title" to Ajax, but refer to $ _POST ["textarea_input"] and $ _POST ["title-input"]
Comment # 4 - You use $("#textarea-input").html() to get the value instead of $("#textarea-input").val() . same for title_input
Here is my working version (just remove the "head").
This is my main.php -
<html> <head> <link rel="stylesheet" type="text/css" href="/stackoverflow/public/jquery-ui-1.8.22.custom.css" media="screen" /> <script src="/stackoverflow/public/jquery-1.7.2.min.js"></script> <script src="/stackoverflow/public/jquery-ui-1.8.22.custom.min.js"></script> </head> <body> <div id="page-wrap"> <div id="tabs"> <ul> <li><a href="#tab-1"> TAB1</a></li> <li><a href="#tab-2"> TAB2</a></li> </ul> <div id="tab-1" class="ui-tabs-panel ui-tabs-hide"> <label for="title_input">Title</label> <input type="text" id="title_input" name="title_input" size="60" autocomplete="off" value="my title"/><br> <label for="textarea-input">Textarea</label> <textarea id="textarea-input" name="textarea-input"></textarea> </div> <div id="tab-2" class="ui-tabs-panel ui-tabs-hide"> </div> </div> </div> <script> var currentTab = 0; $(function() { var $tabs = $('#tabs').tabs({ disabled: [0, 1] , select: function() { console.log("selecting a new tab " + currentTab); if (currentTab == 0) { $.ajax({ type: "POST", url: "tabs.php", data: { "textarea": $("#textarea-input").val(), "title": $("#title_input").val() }, success: function(result) { $("#tab-2").html(result); } }); } } , show: function(event, ui) { currentTab = ui.index; } }); $(".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; }); }); </script> </body> </html>
And this is my "tabs.php"
My working example can be found on my website.
<?php echo "This is the result are you ready?"; if (isset($_POST['title'])){ $title = $_POST['title']; echo ('<div id="title_result"><span id="resultval"><h2>Title Echo result:</h2>'.$title.'</span></div>'); } else{ echo "title_input is not defined!"; } if (isset($_POST['textarea'])){ $textarea = $_POST['textarea']; echo ('<div id="textarea_result"><span id="resultval"><h2>Textarea Echo result:</h2>'.$textarea.'</span></div>'); } ?>
Let me know if anything else.