Jump to content

JS - How to display HTML links based on data in table


Recommended Posts

Hi,

I am a caspio rookie and need some help with my Search and Report Datapage

Basically my table has a field "Membership" which can have 3 levels - Basic, Pro and Premium. Depending on level of membership I need to display a different HTML link in a "Search and Report Datapage".

I looked thru the forum and see that I can retrieve records via

getElementById("InsertRecordMemebership").value OR

getElementById("EditRecordMemebership").value.

Not sure when I should use "InsertRecord" vs "EditRecord".

I'm thinking that I need to run some javascript code and use either jquery's .html() API or innerHTML to accomplish this. Can someone please help me out with this or guide me in the right direction?

Thanks in advance.

Link to comment
Share on other sites

So I tried the following in the HTML block of my Datapage

a) Jquery's html() API (the place where this datapage is deployed has jquery)

var membership = '[@field:Membership]';

if (membership == 'Basic')

{

$("#biz-name").html("[@field:Company_name]");

}

B) innerHTML

var membership = '[@field:Membership]';

if (membership == 'Basic')

{

document.getElementById('biz-name').innerHTML ='[@field:Company_name]';

}

In both cases, when the search returns multiple records, _ONLY_ the 1st record is updated. However it has the value of the _LAST_ record's Company_name.

Does anyone know how to tweak this to make it work on a per-record basis?

I would really appreciate the help.

Link to comment
Share on other sites

Thanks for your suggestion casyana.

Actually I thought about document.write() earlier today morning and tried it out. And it does indeed work, whew!

The reason why I had jumped at innerHTML or .html() first was because document.write() is generally frowned upon, isnt it? I tried it out in Chrome, Firefox and IE 8.0 & 9.0 and it does seem to work. Hoping that this will work across all browsers..

Link to comment
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...
 Share

×
×
  • Create New...