Jump to content

PLEASE HELP! I need a function to occur onClick!


xProteuSx

Recommended Posts

Usually I can figure this out, but I am completely stumped.

 

Say I have a function like this:

 

whatever = new function()

{

alert("Yay");

        }

 

Then I have a link like this in the HTML:

 

<a href="javascript:whatever()">Say Yay!</a>

 

Why does this not work for me????  Please help!  Thank you in advance.

Link to comment
Share on other sites

Usually I can figure this out, but I am completely stumped.

 

Say I have a function like this:

 

whatever = new function()

{

alert("Yay");

        }

 

Then I have a link like this in the HTML:

 

<a href="javascript:whatever()">Say Yay!</a>

 

Why does this not work for me????  Please help!  Thank you in advance.

 

try it this way

function func_name() 
{
    alert("yay");
}

<input type="button" value="Say Yay" onClick="func_name();"/>

Link to comment
Share on other sites

Thanks for your help xcoderx.  I have tried these things already, but it turns out that I was doing this correctly.  I have narrowed it down to this:  one of my variables is not assigning:

 

var outputString = '<table width="650" cellpadding="0" cellspacing="0">

                    <tr valign="top">

                        <td width="300">

                            <a href="http://www.amazon.com/Disciplined-Breakdown-Collective-Soul/dp/B000002JCB/ref=sr_1_1?ie=UTF8&s=music&qid=1261206207&sr=1-1">

                            <img src="img/cover_disk_disciplinedBreakdown.jpg" border="0" />

                            </a>

                        </td>

                        <td width="25"></td>

                        <td>

                            <font class="title">Disciplined Breakdown</font>

                            <br /><br />

                            01. Precious Declaration<br />

                            02. Listen<br />

                            03. Maybe<br />

                            04. Full Circle<br />

                            05. Blame<br />

                            06. Disciplined Breakdown<br />

                            07. Forgiveness<br />

                            08. Link<br />

                            09. Giving<br />

                            10. In Between<br />

                            11. Crowded Head<br />

                            12. Everything<br />

                        </td>

                    </tr>

                </table>';

 

Any idea why outputString = '' ??

Link to comment
Share on other sites

Man, everything I tried the first time works, but it was out of sequence.  I have it all figured out.  Thanks a ton xcoderx.

 

If you're still around, here is my final question:  is there a way to have a link with an onclick clause that goes to a different page and runs a function on that page?

 

For example:

 

I am on index.html where there is a link that looks like this:

 

<a href="about.html" onclick="javascript:runme()">About</a>

 

If you click the link it takes you to the about.html page and runs the function runme() which is scripted on that page.  Is this possible?

Link to comment
Share on other sites

Man, everything I tried the first time works, but it was out of sequence.  I have it all figured out.  Thanks a ton xcoderx.

 

If you're still around, here is my final question:  is there a way to have a link with an onclick clause that goes to a different page and runs a function on that page?

 

For example:

 

I am on index.html where there is a link that looks like this:

 

<a href="about.html" onclick="javascript:runme()">About</a>

 

If you click the link it takes you to the about.html page and runs the function runme() which is scripted on that page.  Is this possible?

 

You can always invoke javascript's function from anchor tag:

<a href="javascript: func();">Cilck me!</a>

 

In your script, put this:

function func() {
    // call the runme function.
    runme();

    // now redirect the page.
    window.location = "about.html";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.