Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 18th, 2007, 06:29 PM
Registered User
 
Join Date: Dec 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default HTML anchor and JS focus not working together

Hi,

I have a form in which there are 2 dropdowns for Country and State respectively (in the middle of the form). When I select a value from the Country dropdown the page refreshes and loads the State dropdown with the relevant state names. I want the page to remain in the same place where it was before refreshing the page (ie., I dont want the page to go to the top after refreshing) and also I want the focus to be on the State dropdown after refershing. For this I created a HTML anchor as below

<a name="cntrystateanchor" />
  <div>
      <select class="small3 formfieldwidth2" name="countryDDList" id="countryDDList" onchange="javascript:getStates();">
    <option value="" selected >- Please Select -</option>
    <% Iterator keys= countrylist.keySet().iterator();
                                   while(keys.hasNext() ){
                                  ........... <% } %>
    </select>
  </div>

When the page is done with refreshing I am doing the following

document.registrationForm.stateDDlist.focus();
document.location = "#cntrystateanchor";

My page is staying at the same place after refreshing but the focus is not getting set to the 'States' dropdown. If I remove the "document.location = "#cntrystateanchor";" the focus is getting set correctly to the 'States' dropdown but as expected the page is going to the top after refreshing (as I removed the document.location).

Can someone please help me with this.

Thanks,
Sudhir





Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching for body element in an html not working aldwinenriquez XML 8 August 28th, 2008 05:56 AM
anchor link not working in IE6 sbkumar CSS Cascading Style Sheets 2 July 29th, 2008 11:27 AM
only do HTML/ASP when JS variable = true crmpicco Javascript How-To 1 July 19th, 2005 05:06 AM
Myasp code is not working while html give results Raz Muhammad .NET Web Services 1 March 3rd, 2004 04:21 AM
Trigger a JS function on loss of focus apd8x Javascript 1 July 14th, 2003 09:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.