Results 1 to 3 of 3
  1. #1
    Super Moderator WebGenii's Avatar
    Join Date
    Jan 2001
    Redcliff, Alberta, Canada
    Thanked 5 Times in 5 Posts

    Javascript move to Link

    Here's what I'd like to do.
    I'm using Javascript to validate the contents of a form. If a user hasn't completed various portions. I have alert boxes popping up appropriately. Since the form is rather long I'd also like to pull the user back to the offending location on the form.
    The problem: I have no idea how to trigger <a href=#"mylocation"> without using a new window, which I don't want to do.

    Any suggestions?
    [b]Catharine Richardson (WebGenii)
    WebGenii Home Page
    Moderator: Spreadsheets, Other MS Apps, Presentation Apps, Visual Basic for Apps, Windows Mobile

  2. #2
    Silver Lounger
    Join Date
    Jan 2001
    Indianapolis, Indiana, USA
    Thanked 0 Times in 0 Posts

    Re: Javascript move to Link

    Here are a few thoughts:

    1) Rather than firing a page navigation, why not just set focus (yourField.focus()[img]/forums/images/smilies/wink.gif[/img] to the appropriate offending field. This will automatically scroll the browser to the offending field. The only problem is that the field will display at the very top of the page, cutting off any text or instructions above the field.

    2) I realize that you're using client-side validation, but this suggestion is for the benefit of anyone who may choose to use Server-side validation as an option. With server-side validation you can force the page to jump to a desired location using an Anchor, just like you described. The only catch (especially for non ASP.NET platforms) is that you will have to submit the page back to itself and re-populate the controls with their respective values (ASP.NET does this automaticlly with its Viewstate functionality).

    3) The only other options I can imagine would involve using Javascript to scroll the page. I imagine this is not very difficult, but I've never bothered trying to do it. I would bet that your page will need to be constructed with absolute sizes (which I hate doing due to the variety of resolutions) and you will probably need to include support for multiple browsers, depending on your audience.

    (If you're not in the market for Server-side validation, Option 1 should work fairly well...)
    Hope this helps

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 93 Times in 89 Posts

    Re: Javascript move to Link

    I vaguely recall another thread about scrolling the page... but if that doesn't surface quickly in a search, you always can emulate a user button click using the method. I guess this assumes you have an appropriate button. (I can't remember whether it works with links.) You could try setting the page's location.hash value; it is read-write and contains the current anchor, e.g., #PartB, but I haven't tested what happens if you assign it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts