Click here to Skip to main content
15,884,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys..

I have problem with my cursor position after refresh my page.

Here is JS

function checkAvaib()
{
    var x=document.getElementById("form");
    x.action="student_new.php";
    x.target="_self";
    x.submit();
}


Here is HTML

<input type="text" name="user_id" id="user_id" maxlength="10" value="<?php echo $_REQUEST["user_id"];?>"  önblur="checkAvaib()" tabindex="15"/>

<input type="text" name="name" id="name"  value="<?php echo $_REQUEST["name"];?>" tabindex="16"/>


When I start enter at user_id field and then tab to the next field(name). It will refresh the page and cursor position going to the first tab/field.
Is it possible to point the cursor to the next tab/field after refresh?

Thanks in advance.
Posted

In general you have to hold the things in a viewstate variables which you want to access when you come back on the page after post backs.

I dont know y are u submitting when you tab to next control, anyways you can make some viewstate variable or session or hidden field on your page that records the control you are at. then after the referesh you know which control you were at and you can set the focus of the cursor next to the control you just recorded.
 
Share this answer
 
v2
Comments
needphp 10-May-11 22:36pm    
hi saxenaabhi6, thanks for reply.

Actually i using onblur to check either user already in db or not. probably u can give me some example to get better understanding.
saxenaabhi6 10-May-11 22:43pm    
hi,
I am not a php guys, but as mark said you could use ajax in php to check weather the id already exists in db or not http://www.w3schools.com/PHP/php_ajax_database.asp.
saxenaabhi6 10-May-11 22:54pm    
if you want to do it as a hack (bad way i think) ... read this on how session works in php http://php.about.com/od/advancedphp/ss/php_sessions_2.htm
then make a session and set it to some value ( say 1) when you submit on blur. then in the script tag of page checks if the value is 1 then set the focus on your next control 'name'.
needphp 11-May-11 20:38pm    
i'm using session and its works. thank you so much..
saxenaabhi6 11-May-11 20:58pm    
great..
though i would again stress you to learn and use ajax, trust me its beautiful :)
You would need some mechanism to tell the page it has been reposted and it should start with the focus on the second field, a query string parameter perhaps.

Or you could use more modern and user friendly techniques, like AJAX, and not post the page when loosing focus.
 
Share this answer
 
Comments
needphp 10-May-11 22:44pm    
hye Mark Nischalke..

I got what u said. I also think about Ajax. but if i change to ajax, i need to re-arrange the whole code. thats why i avoid using AJAX.

Probably you can give me some example, so that i can works on it. I'm little bit blur on this.
thank you so much...
[no name] 11-May-11 7:31am    
There are plenty of examples of AJAX. Look for them.
needphp 11-May-11 20:37pm    
thank you for ur suggestion for a while, i hv decided to use session. Later i'll try to works on AJAX. thank you
you can maintain cursor position using maintainscrollpositiononpostback="true" in page directive or smartnavigation="true" or using updatepanel .
 
Share this answer
 
Comments
[no name] 11-May-11 7:29am    
Did you notice the PHP in the OPs question? ASP.NET attributes and controls won't work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900