Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all, I think you should use <a href="http://getfirebug.com/" rel="nofollow noreferrer">Firebug</a> to check on what is actually rendered as html. It also help uncovering some javascript errors or fail-to-load resources.</p> <p>Second, you should check if the javascript get called in the first place, by placing an <code>alert('come here');</code> right at the beginning of isfilipinoCitizen(). After that, an alert in the first condition. Javascript is a special language, we must be careful when dealing with it :) :</p> <pre><code> &lt;script type="text/Javascript"&gt; function isfilipinoCitizen() { alert("come here"); var selected = "${accountInfo?.filipinoCitizen}"; if(selected == "1"){ alert("come there"); return true; }else{ alert(selected) alert("You must be a Filipino citizen to register!") document.location.href = "myhomepage"; } } &lt;/script&gt; </code></pre> <p>At last (after you guarantee that your javascript function get called properly), you must do more than "document.location.href" to prevent the form from submitting. For quick effect, I would recommend <a href="http://api.jquery.com/" rel="nofollow noreferrer">jQuery</a> and the <a href="https://stackoverflow.com/questions/8888164/prevent-form-from-submitting-to-a-different-page">onSubmit() event</a>. If you like pure javascript solution, you can follow the solution that Galm and Anuj propose: put onsubmit into the tag:</p> <pre><code>&lt;g:form name="myForm" action="myaction" onsubmit="return isfilipinoCitizen()"&gt;...&lt;/g:form&gt; </code></pre> <p><strong>In the failing case, please remember to return false :)</strong></p> <p>P/s: Inserting <code>${accountInfo?.filipinoCitizen}</code> directly to javascript might work, but it's not a best practice. Transfering "isFilipinoCitizen" as a parameter to the javascript function is better.</p> <p><strong>Another usability thought</strong>: if you already know which user has the right to register, why must we wait until the user fill all the form, to tell them that they must be Filipino citizen to register? Why aren't users notified before(after page load) ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload