PhotoDune

javascript undefined??

7 posts
  • Exclusive Author
  • Malaysia
  • Has been a member for 1-2 years
  • Bought between 10 and 49 items
kakinetwork says

this is my index.php

<script src="test.js?country=japan" type="text/javascript"></script>

this is my test.js


var url = document.location.href;
url = url.split("?country=");
alert(url[1]);
document.write(url[1]);

when I visit index.php, the page show undefined.. why not showing japan? can help me fix this?

123 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 500 and 999 users
jackpotsoft says
kakinetwork said
this is my index.php
<script src="test.js?country=japan" type="text/javascript"></script>

this is my test.js


var url = document.location.href;
url = url.split("?country=");
alert(url[1]);
document.write(url[1]);
when I visit index.php, the page show undefined.. why not showing japan? can help me fix this?

Would Share Complete Error Your Receive.

In case of Java You should Try Java Error Console . It shows Error On page load.

Since you are getting Error on index.php , It may be some PHP error too

7 posts
  • Exclusive Author
  • Malaysia
  • Has been a member for 1-2 years
  • Bought between 10 and 49 items
kakinetwork says

try take a look at http://test.easila.com/

I try to show the word japan.. you can view source

123 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 500 and 999 users
jackpotsoft says
kakinetwork said
try take a look at http://test.easila.com/ I try to show the word japan.. you can view source

Cause You have not provided any parameter to URL

Try this now

http://test.easila.com/index.php?country=japan http://test.easila.com/index.php?country=USA http://test.easila.com/index.php?country=AnyText
459 posts
  • Bought between 10 and 49 items
  • Contributed a Blog Post
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 4-5 years
  • Microlancer Beta Tester
  • Referred between 100 and 199 users
  • Sold between 10 000 and 50 000 dollars
+1 more
omarabid says
This is the bad part
var url = document.location.href;
It doesn’t return the script URL , but the page URL . This is how you should do it
var url = document.getElementsByTagName('script')[0].src;
Assuming that script is put at the top. However, I don’t recommend that way. Create a global variable where you put your parameters
<script>
var param = {
country: japan
};
// when document is ready
$(document).ready(function() {
// load your scripts
});
</script>
7 posts
  • Exclusive Author
  • Malaysia
  • Has been a member for 1-2 years
  • Bought between 10 and 49 items
kakinetwork says

thanks omarabid.. you opened my eyes to solve my problem :)

by
by
by
by
by