0

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

2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by ajbest
0

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();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.