If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

jquery swap content make page default on load

I need con1 to show active and be loaded onload of page.

this is my code to swap content. I am using a external php page to swap out content when the id of con1 con2 and so on our clicked.

I want to make con1 show onload of page and the link to show active but when you go to the page it only shows my div with no content till a link is clicked. once link is clicked it hovers shows active and works great.

thanks for your response. but im new to jquery and im having problems chaining functions together or adding them in one set of script. could you write that out with in my script so i can understand it better?

for example if if i am displaying information from the php page in #myDiv

$("#myDiv").html(data).show();

can I not just change this code to make it load the first link and then continue on swapping out data?

i don't know will it be better to have only one page but if you decide to make it on one page you can make various php-functions for various actions and you can call the function you need by passing, for example, 'mode' or 'act' or whatever you like to name it and then use switch:

Code:

<?php
here goes your php-code
and at the end of the code you put this
$mode=(!empty($_GET['mode']))?$_GET['mode']:$_POST['mode'];
switch($mode){
case 'f_1': f_1();break;
case 'f_2': f_2();break;
default: here goes you default function of nothing;break;
}
?>

xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"yyy: facepalm

$(document).ready(function(){
$('a.topnav').each(function(){
$(this).click(function(){
$("a.topnav").removeClass("active");
$(this).addClass("active");
/*
we have 1.php and 2.php for getting some data
let's set the menu links id's so that every id will contain the name of the certain php page (without '.php')
this way we can get this as a substring taken from the link id (see the two lines of the code below)
*/
var ID=$(this).attr('id');
var php_page=ID.substring(ID.indexOf('_')+1,ID.length);
/*and now we can get the appropriate data*/
$.post(php_page+'.php',function(data){$("#myDiv").html(data);});
});
});
$('#topnav a:first').click();
});

Last edited by Padonak; 04-23-2013 at 01:41 PM.

xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"yyy: facepalm