vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Checking a profile field's value and executing javascript (https://vborg.vbsupport.ru/showthread.php?t=322486)

m0nde 04-29-2016 10:06 PM

Checking a profile field's value and executing javascript
 
I've created a custom profile field with several radio buttons. Each radio button has a text value assigned to it and the user must choose a single value from this list.

I want to branch depending on the string value of this field in a template and execute a separate script based on each value.

What I've tried is:
Code:

<vb:if condition="$memberinfo['field6'] = 'x'"><script type"text/javascript" src="x.js"></script></vb:if>
<vb:if condition="$memberinfo['field6'] = 'y'"><script type"text/javascript" src="y.js"></script></vb:if>
<vb:if condition="$memberinfo['field6'] = 'z'"><script type"text/javascript" src="z.js"></script></vb:if>

But all of the scripts execute at once.

Dave 04-29-2016 11:22 PM

Try changing the single = (declaring a variable) to == (comparing a variable).

m0nde 04-30-2016 12:35 AM

Thank you. I'm not at all experienced in doing any of this.

--------------- Added [DATE]1461985905[/DATE] at [TIME]1461985905[/TIME] ---------------

In the end, in addition to my error with declaring instead of comparing values, I found that I needed to use $bbuserinfo instead of $memberinfo. I still don't understand when to use which.

Scandal 05-01-2016 03:11 PM

Quote:

Originally Posted by m0nde (Post 2569862)
Thank you. I'm not at all experienced in doing any of this.

--------------- Added [DATE]1461985905[/DATE] at [TIME]1461985905[/TIME] ---------------

In the end, in addition to my error with declaring instead of comparing values, I found that I needed to use $bbuserinfo instead of $memberinfo. I still don't understand when to use which.

You should use $bbuserinfo for the user who load the page.
If you need to apply code for the user of an item (for example on the postbit/postbit_legacy), you could use $post['fieldX'] (= it will return the fieldX value for the user of the post). ;)


All times are GMT. The time now is 12:47 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01969 seconds
  • Memory Usage 1,716KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete