Hi..

I am doing an online quiz software.I have total 100 questions with 5 in each page.I want to go to a particular question number and I want to fix the focus on that question(Not on the top of the page).Each question is inside a label.I am calling a function for that.I used following code.

function goto_quest(qid,cid)
{
var serial=$('#gotq').val(); 
var total_quest=$('#total_quest').val(); 
var perpage=$('#perpage').val(); 

$(document).ready(function()
{   
$.post("gotopage.php", {serial:serial,cid:cid,perpage:perpage,total_quest:total_quest},function(data)
                        {
var serial1=parseInt(serial)-1;

var lid="lab"+serial1;

window.location = "example.php?page="+data;

alert(lid);

document.getElementById(lid).scrollIntoView();
document.getElementById("gotq").selectedIndex=serial1;
 });
 });
}

The script working fine if I use an alert on line number 19.If I comment the alert focus is not working

I am a little confused on what your are trying to do but in order to set the focus of an input element given the id for that input you would use something like

document.getElementById('your_element_id').focus();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.