Jump to content

Evaluating a field value with javascript


Recommended Posts

I have several fields (Comments1, Comments2, etc.) that I want to place on a details page. The following statement will write the contents of the field

document.write('[@field:Comments1]'); to the details page. I know since it works I should just run with it but...

Rather than repeat the document.write statement for each comments field I thought I would use a for (i = 1; i <= 8; i++) statement to save a few lines of code. My problem occurs when reconstructing the name of the comments field each time it needs to be written '[@field:Commentsi]'

Here is what I tried:

var Comments = "'"+"["+"@"+"field"+":"+"Comments"+"1"+"]"+"'"; // I know if this can be made to work that +"1"+ needs to become +i+

FYI -- Grouping the above code in longer strings such as "'[@field:Comments"+i+"]'" did not write correctly which is why I broke it up

The following statement (unsurprisingly) will not write the contents of the field, it writes the value assigned to the Comments variable

document.write(Comments); // Value written is '[@field:Comments1]' rather than the value contained in the field

My question:

Is there any javascript command/substitution that will evaluate whether a string like '[@field:Comments1]' has a value assigned to it? I tried a function called eval() but that did not do the trick or I didn't use it properly.

document.write(eval(Comments));

If it isn't obvious - I don't do much coding in javascript :)

Link to comment
Share on other sites

Hi,

If you only wanted to display some table fields on HTML blocks on a details page, actually no need to use Javascript at all. Simple enable advanced options and parameters on the second screen (http://howto.caspio.com/parameters/enab ... eters.html), and go directly to the 'configure details page fields' screen, where you can insert HTML blocks. And in the HTML blocks, you can put any HTML or Javascript code you wanted to use to customize the DataPage, and when it's needed to refer to any table field, just select and insert it by using the little insert button on bottom right of the HTML block (http://howto.caspio.com/parameters/disp ... eters.html).

Hope this helps.

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...
×
×
  • Create New...