vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   Javascript confirmation box (https://vborg.vbsupport.ru/showthread.php?t=246826)

Falcon Capt 07-18-2010 12:38 PM

Javascript confirmation box
 
I am trying to use the following script to create a Confirmation Popup box for my "Mark All Forums Read" link, but it isn't working.

In my Navbar template I placed the following at the top:

Code:

<vb:literal>
<script>
<!--
function markAsRead()
{
 var markRead= confirm("Do you really want to mark all forums as read?");
 if (markRead== true)
 { window.location="forumdisplay.php?{vb:raw session.sessionurl}do=markread&amp;markreadhash={vb:raw bbuserinfo.securitytoken}";
 }
 else
 {   
  }
}
//-->

</script>
</vb:literal>


I changed the link for "Mark All Forums Read" to:

Code:

<a href="javascript:markAsRead();"><b><font color=red>{vb:rawphrase mark_forums_read}</font></b></a>



I end up getting the following error in my browser when trying to follow the link:

Quote:

Invalid Forum specified. If you followed a valid link, please notify the administrator

I noticed when the page changes, the URL shows up as: http://www.mysite.com/forumdisplay.php?{vb:raw session.sessionurl}do=markread&markreadhash={vb:ra w bbuserinfo.securitytoken}

It looks like the hash and security tokens are not being passed in the Java Script as they were in vB3.




I was able to use the following in vB3.8.5 and it works fine, but it isn't working in vB4.x:

Code:

<script>
<!--
function markAsRead()
{
 var markRead= confirm("Do you really want to mark all forums as read?");
 if (markRead== true)
 { window.location="forumdisplay.php?$session[sessionurl]do=markread&amp;markreadhash=$bbuserinfo[securitytoken]";
 }
 else
 {   
  }
}
//-->

</script>

Code:

<a href="javascript:markAsRead();">$vbphrase[mark_forums_read]</a>

Any help would be greatly appreciated!



.

Falcon Capt 07-19-2010 06:23 PM

* Bump *

Boofo 07-19-2010 07:17 PM

Try adding the javascript to the headinclude or header template.

Guest190829 07-19-2010 07:36 PM

The problem is you wrapped the javascript around <vb: literal> tags, which you should do, but that means none of the {vb: raw } tags are being parsed in the script.

Maybe try passing this data through the function?

Code:

<a href="javascript:markAsRead({vb:raw session.sessionurl},{vb:raw bbuserinfo.securitytoken );">{vb:rawphrase mark_forums_read}</a>
Code:

<vb:literal>
<script>
<!--
function markAsRead(session, markreadhash)
{
 var markRead= confirm("Do you really want to mark all forums as read?");
 if (markRead== true)
 { window.location="forumdisplay.php?" + session + "do=markread&amp;markreadhash=" + markreadhash;
 }
 else
 {   
  }
}
//-->

</script>
</vb:literal>


Falcon Capt 07-19-2010 07:51 PM

Quote:

Originally Posted by Boofo (Post 2071709)
Try adding the javascript to the headinclude or header template.

Tried both, no change.

Quote:

Originally Posted by Danny.VBT (Post 2071715)
The problem is you wrapped the javascript around <vb: literal> tags, which you should do, but that means none of the {vb: raw } tags are being parsed in the script.

Maybe try passing this data through the function?

Code:

<a href="javascript:markAsRead({vb:raw session.sessionurl},{vb:raw bbuserinfo.securitytoken});">{vb:rawphrase mark_forums_read}</a>
Code:

<vb:literal>
<script>
<!--
function markAsRead(session, markreadhash)
{
 var markRead= confirm("Do you really want to mark all forums as read?");
 if (markRead== true)
 { window.location="forumdisplay.php?" + session + "do=markread&amp;markreadhash=" + markreadhash;
 }
 else
 {   
  }
}
//-->

</script>
</vb:literal>


I tried the above but get a "Syntax Error".

I think we are getting closer as it makes sense that the vb:literal tags are causing the noparse.

Guest190829 07-19-2010 07:54 PM

What's the syntax error? I see already that I missed a ")"

so,

Code:

<a href="javascript:markAsRead({vb:raw session.sessionurl},{vb:raw bbuserinfo.securitytoken});">{vb:rawphrase mark_forums_read}</a>
might fix it.

Falcon Capt 07-19-2010 08:07 PM

Quote:

Originally Posted by Danny.VBT (Post 2071725)
What's the syntax error? I see already that I missed a ")"

so,

Code:

<a href="javascript:markAsRead({vb:raw session.sessionurl},{vb:raw bbuserinfo.securitytoken});">{vb:rawphrase mark_forums_read}</a>
might fix it.

Still no-go.

It doesn't tell me what the Syntax Error is.

When I hover over the link, it shows:

javascript:markAsRead(,1279577127-xxxxxxxxxxxxxxxxxxx)

It appears there might be a hash missing. Also, when I click on the Mark All Read button, I don't get the confirmation popup either.

Guest190829 07-19-2010 08:26 PM

Try:

Code:

<a href="javascript:markAsRead('{vb:raw session.sessionurl}','{vb:raw bbuserinfo.securitytoken}');">{vb:rawphrase mark_forums_read}</a>

Falcon Capt 07-19-2010 08:36 PM

Quote:

Originally Posted by Danny.VBT (Post 2071736)
Try:

Code:

<a href="javascript:markAsRead('{vb:raw session.sessionurl}','{vb:raw bbuserinfo.securitytoken}');">{vb:rawphrase mark_forums_read}</a>

EXCELLENT!!!

That appears to have done the trick!

THANK YOU for your help!!! :up::up::up::up::up::up::up::):):):):)

Boofo 07-19-2010 08:43 PM

Where did you end up putting the js code?


All times are GMT. The time now is 09:11 AM.

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.01687 seconds
  • Memory Usage 1,747KB
  • 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
  • (12)bbcode_code_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete