Jump to content
hrdickinson

How To Display Different Href Based On Authfield

Recommended Posts

I have a HTML datapage which is the user' s main menu to my app.  Now I would like to test whether the user is restricted in it's use of the first of four menu items.  I have the following code, but it returns "file or directory not found" when I preview it and choose the 1st menu item:

 

<script>

window.onload = testFormRes;

function testFormRes()
{
var dynLink;

if ("[@authfield:Restricted^]"=="yes"){

dynLink="https://c0ect240.caspio.com/dp.asp?AppKey=eeda30004146e1be17fe4f64a319";
}
else{

dynLink="https://c0ect240.caspio.com/dp.asp?AppKey=eeda3000a155f226d27146b0ae20";

}
}
</script>

<div id="menu-mobile">
 
  <div id="row">
    <h1><i>[@authfield:Cust_Name]</i></h1>
    <h2>Main Menu - Res</h2>
  </div>
  <div id="row">
    <div id="mobileNavagtion">


      <ul>
        <li><a href=("dynLink")  class="btnPatrolForm">ActivityForm</a></li>
        <li><a href="https://c0ect240.caspio.com/dp.asp?AppKey=eeda3000a31708e7da464d9e9b63" class="btnPostOrders">Post Orders</a></li>
        <li><a href="https://c0ect240.caspio.com/dp.asp?AppKey=eeda3000d7e592f401a541d4b948" class="btnReportsMain">Reports</a></li>
        <li><a href="https://c0ect240.caspio.com/folderlogout" class="btnLogout" class="btnLogout">Logout</a></li>

      </ul>
    </div>
  </div>

 
</div>

 

As one can probably detect, I am a novice at coding, any help would be appreciated!

 

Richard
 

Share this post


Link to post
Share on other sites

You're using a JS var outside of a JS function. - <a href=("dynLink")....

Rather, you need assign the href from within the JS function.

You can also simplify your code by removing the else and simply starting with the link that should be there when the "if" fails

<script>

window.onload = testFormRes;

function testFormRes()
{
  var dynLink;
  var linkEle = document.getElementById('dynLinkEle');

if ("[@authfield:Restricted^]"=="yes"){
  dynLink="https://c0ect240.caspio.com/dp.asp?AppKey=eeda30004146e1be17fe4f64a319";
  linkEle.href = dynLink;
  }
}
</script>

<a id="dynLinkEle" href="https://c0ect240.caspio.com/dp.asp?AppKey=eeda3000a155f226d27146b0ae20"  class="btnPatrolForm">ActivityForm</a>

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...