SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    760
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    After alert click, go to anchor text in site

    I have an alert that is checking if a form has been filled in, and basically I want to add some extra feedabck so that when the click the 'OK' of the alert button they will travel to that position in the page.

    This is what I got so far

    Code:
    else if (document.form2.primarycause.value == "0")
    {
    alert("Most likely or actual primary and secondary outcome - Please complete all required fields");
    return false;
    }
    And also add '1' to value of a variable in php.

    Code:
    $red_line = "";

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    If the element in question has an id you can set window.location.hash to achieve this:

    Code JavaScript:
    window.location.hash="nameOfId";

    Or, is you want to do something a little more complex, find out the position of the element on the page and animate the jump to this point (maybe with the jQuery scrollTo plugin)

  3. #3
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    760
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Pullo,

    No thats perfect, it works great.

    What is the usual method of highlighting a required form element.

    I thought about using a variable in php and then using an if statement to underline the label in red, but when I tried to make the variable a different value as below, it didnt quite do what I needed.

    Code:
    <?
    $red_Line="";
    ?>
    
    if (document.form2.hazardornearmiss.value == "0") 
    {
        alert("Hazard or Near Miss? - Please complete all required fields");
        window.location.hash="Hazard";
    	<? $red_Line="1"; ?>
    	return false;
    }
    
    <td width="193px" style="vertical-align:top;">
    <a name="Hazard" id="Hazard"></a>
    <? if ($red_Line=="") { ?>
    <span style="color:#900">*</span> Hazard or near miss?
    <? } else { ?>
    <span style="color:#900">*</span><span style="border-bottom:#990000 solid 1px">Hazard or near miss?</span>
    <? } ?>
    </td>
    Its very basic I know, but to me it doesnt seem right.

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,313
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    Hi there,

    Quote Originally Posted by multichild View Post
    What is the usual method of highlighting a required form element.
    I would assign this element a class of "field_with_errors" or something similar.
    You can do this in both your JS and PHP, then style it accordingly.

    I would also put a small summary of why the form submission was not successful somewhere near the form.


Bookmarks

Posting Permissions

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