0

I'm using the below code and it seems to only be half working.

I am trying to make it so when a user clicks on the url the text for the a href tag changes.

For example, a user goes on my site. When they click the url 'Love station' it replaces the text and url to 'Dump Station' if the user then clicks 'Dump station' again it changes it back to 'Love Station'

At the moment it changes the text to dump station, but once i click it again, nothing happens.

Any ideas?

<script type="text/javascript">
function lovestation() {

$.get("../lovestation.php?id=<?echo $sta->ID;?>");
document.getElementById('love').innerHTML="Dump <? echo "$sta->Title";?>"
document.getElementById('love').id="dump"
document.getElementById('love').onclick="dumpstation();"

return false;

}



function dumpstation() {
$.get("../dumpstation.php?id=<?echo $sta->ID;?>");
document.getElementById('dump').innerHTML="Love <? echo "$sta->Title";?>"
document.getElementById('dump').id="dump"
document.getElementById('dump').onclick="dumpstation();"
return false;
}


</script>
5
  • 1
    For starters, check your id= statements. Commented Aug 2, 2014 at 14:34
  • What could document.getElementById('dump').id="dump" possibly do? Commented Aug 2, 2014 at 14:40
  • it will not run because document.getElementById('love').innerHTML="Dump <? echo "$sta->Title";?>" should be document.getElementById('love').innerHTML="Dump <? echo '$sta->Title';?>" did you just noticed i have change one double coutation mark to single coutation mark Commented Aug 2, 2014 at 14:52
  • and where is the semicolon after id="dump" ? Commented Aug 2, 2014 at 14:54
  • @anni. That will litterly echo the string "$sta->Title" not the value that is assigned to the variable. Commented Aug 2, 2014 at 14:54

1 Answer 1

2

You are referencing the onclick to a string: document.getElementById('dump').onclick="dumpstation();".
It should be :

document.getElementById('dump').onclick = dumpstation;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.