Jump to content

changing a function dynamically


9three

Recommended Posts

Hey,

 

I have a link that contains a javascript function:

 

<a href="#" onclick="refresh('<?php echo $_GET['place']?>');return false;" id="refresh">

 

What I need to do is change that function refresh() completely out with another function that I have.

 

I tried doing the following, but I failed:

 

$('#refresh').click(function () {
  $('#refresh').bind('onclick', getSorted());
  //also tried attr
});

 

I may have the syntax wrong but when I did try to implement it, I clicked on the link and it lagged my screen for like 3 seconds, and it didn't change out my function.

 

Does anyone know how to replace a onclick function with a completely different one?

 

Thanks

Link to comment
Share on other sites

Heres a scenario:

 

1. User gets to the page and hits the button "refresh". The button has a function that calls an ajax file to retrieve the latest information, this function is called refresh(). The refresh takes a paramater, place. The place is for where the user is. If the user is in the home page, then I do place = home, so then it translate into refresh('home').

 

2. User clicks a letter from "A - Z" that I added. When the user clicks on a letter, the refresh button is dynamically changed to another function. This function is called getGenreSorted(). It takes 1 parameter, which is the letter the user clicked on. If the user clicked on A then it would translate into getGenreSorted('A').

 

3. Now the refresh button, when clicked, will refresh content that has an "A" (or whatever letter the user clicked). The refresh button now stores the getGenreSorted() function instead of the refresh() function.

 

What's happening right now is that it crashes at step 2.

 

Hope this has cleared it up some more.

 

Thanks for the help so far.

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.