PDA

View Full Version : Quick-Qoute hack (need help with javascript)..


EvilLS1
06-25-2003, 02:56 AM
Hi,
Last night I started working on what I believe will be a very useful hack. It will allow you to directly reply (with a quote) to any post in a thread without having to load the newreply page..

In each post will be a small "QuickQoute" button.. When you click it a reply box will instantly drop down below that post.

I've put together an html example to show you exactly what I'm talking about.

Note: View this with Internet Explorer (6.0)... I haven't got around to making it work with other browsers but that won't be a problem.

Click here to see how QuickQoute works. (http://modernmusclecars.net/QuickQuote.html) (Click the QuickQuote button).

Anyway, what I will do is add some code to functions.php to check permissions, and then if everything is all good a variable will call the "QuickQoute" template which contains the reply form.. This variable will be placed in the postbit template.

Adding the PHP code isn't a problem.. I already know how to do that.

This is the problem:
Each form must have a unique ID or it will not work.. So I need to place some kind of variable that will display a unique value inside the javascript function.

Making it work in an HTML page is easy because you can define each form id yourself.. But making it work in the postbit is a bit more of a challenge because each postbit is generated dynamically (the same form will show up in each post).

Originally I planned to use the postid since it would be unique for every post, but I soon realized that php variables will not work in javascript functions.

Here's an example to show you what I need:

Example:
-----------------------------------------------

<script language="javascript">
function showDiv(objDiv)
{
Obj=eval((navigator.appName=="Netscape")?"document.layers['"+objDiv+"']":"document.all['"+objDiv+"'].style");
Obj.visibility="visible";
}
function hideDiv(objDiv)
{
Obj=eval((navigator.appName=="Netscape")?"document.layers['"+objDiv+"']":"document.all['"+objDiv+"'].style");
Obj.visibility="hidden";
}
</script>

<form enctype="multipart/form-data" action="newreply.php" name="vbform" method="post" onSubmit="return validate(this)">

<INPUT type="button" size="1" value="QuickQuote" name=button1 onClick="javascript:showDiv('formIDvariable ')">

<INPUT type="button" value="Hide" name=button2 onClick="javascript:hideDiv('formIDvariable ')">

<div id="formIDvariable " style="visibility:hidden;position:absolute">

~~~~~Reply Form goes here~~~~~

</div>

-------------------------------------------------------

Basically what I need is some way to change the form ID variable (highlighted in orange) to something unique for each post. The $post[postid] would be perfect if it were possible to make a php variable work with a javascript function, but that won't work. So I'm wondering if there's any way to do this with javascript?

I hope I've explained this clearly, but if you have no idea what the heck I'm talking about just let me know and I'll try again.

Any help would be appreciated.

SmEdD
06-25-2003, 05:39 AM
<script language="javascript">
function showDiv(objDiv)
{
Obj=eval((navigator.appName=="Netscape")?"document.layers['"+objDiv+"']":"document.all['"+objDiv+"'].style");
Obj.visibility="visible";
}
function hideDiv(objDiv)
{
Obj=eval((navigator.appName=="Netscape")?"document.layers['"+objDiv+"']":"document.all['"+objDiv+"'].style");
Obj.visibility="hidden";
}
</script>

<form enctype="multipart/form-data" action="newreply.php" name="vbform" method="post" onSubmit="return validate(this)">

<INPUT type="button" size="1" value="QuickQuote" name=button1 onClick="javascript:showDiv('<?php echo $post[postid]; ?>')">

<INPUT type="button" value="Hide" name=button2 onClick="javascript:hideDiv('<?php echo $post[postid]; ?>')">

<div id="<?php echo $post[postid]; ?>" style="visibility:hidden;position:absolute">

And if that works can you please add me to the credits in the install.txt or what ever, thanks.

EvilLS1
06-25-2003, 06:12 AM
Thanks for the reply SmEdD, but that won't work either (remember, this will be placed in the postbit template).

And yes, if anyone can help me solve this problem I will gladly put their name in the hack credits. ;)

EvilLS1
06-26-2003, 12:35 AM
Problem solved! After doing some reading on javascript I found out that javascript variables cannot start with a number (like the postid).. So I fixed it by adding a prefix to the variable like so:

onClick="java script:showDiv('pf$post[postid] ')"

Now its working. :) For those who are interrested, the hack has been released here:
https://vborg.vbsupport.ru/showthread.php?s=&threadid=54759

Dean C
06-26-2003, 10:12 AM
Sounds like a really nice hack ;)

- miSt