Help calling a function

Joined
Mar 14, 2023
Messages
8
Reaction score
0
Can someone please give me some advise here. I'm not a super javascript programmer but i can get around a little. i'm either overlooking something or i'm doing something really wrong.

ultimately i'm trying to have php call a javascrpt function. but i can only get it to work with double quotes around the data field and not sure why.

function:
JavaScript:
function readOnlyGame(title, date, data) {
            window.location = "../pages/forward_readonly.html?data=" + escape(data);

    }

calling using php (NOT WORKING).
* var d is this WITHOUT quotes:
Code:
&teams=8&sets=1&groups=1&modeVal=dko.html&modeTxt=Double%2520Elimination&title=My%2520Tournament%2520Name%252056555&shuffleLooser=true&?data=&matchDetail=11.3.2023%20Double%20Elimination%2C%208%20Teams&matchData=shuffleOrder%253D0.23023348552613987%25252C0.013753975196499457%25252C0.183546196452959%25252C0.18362271900778593%25252C%253Bteam0_1%253Dvjgv%252520ju%253Bresult0_1_0%253D1%253Bteam0_2%253Douhoiunb%253Bresult0_2_0%253D2%253Bteam4_1%253Douhoiunb%253Bresult4_1_0%253D%253Bteam4_2%253D%253Bresult4_2_0%253D%253Bteam6_1%253D%253Bresult6_1_0%253D%253Bteam6_2%253D%253Bresult6_2_0%253D%253Bteam1_1%253D%253Bresult1_1_0%253D%253Bteam1_2%253D%253Bresult1_2_0%253D%253Bteam2_1%253D%253Bresult2_1_0%253D%253Bteam2_2%253D%253Bresult2_2_0%253D%253Bteam5_1%253D%253Bresult5_1_0%253D%253Bteam5_2%253D%253Bresult5_2_0%253D%253Bteam3_1%253D%253Bresult3_1_0%253D%253Bteam3_2%253D%253Bresult3_2_0%253D%253Bteam7_1%253D%253Bresult7_1_0%253D%253Bteam7_2%253D%253Bresult7_2_0%253D%253Bteam9_1%253D%253Bresult9_1_0%253D%253Bteam9_2%253D%253Bresult9_2_0%253D%253Bteam11_1%253D%253Bresult11_1_0%253D%253Bteam11_2%253D%253Bresult11_2_0%253D%253Bteam12_1%253D%253Bresult12_1_0%253D%253Bteam12_2%253D%253Bresult12_2_0%253D%253Bteam8_1%253D%253Bresult8_1_0%253D%253Bteam8_2%253Dvjgv%252520ju%253Bresult8_2_0%253D%253Bteam10_1%253D%253Bresult10_1_0%253D%253Bteam10_2%253D%253Bresult10_2_0%253D%253Bteam13_1%253D%253Bresult13_1_0%253D%253Bteam13_2%253D%253Bresult13_2_0%253D%253B&matchDetail=11.3.2023 Double Elimination, 8 Teams&matchData=shuffleOrder%3D0.21865197396416836%252C0.9990132343964383%252C0.08503560342563254%252C0.5529512381303724%252C0.06779914862511305%252C%3Bteam0_1%3Dvjgv%2520juxccccc%3Bresult0_1_0%3D1%3Bteam0_2%3Douhoiunb%3Bresult0_2_0%3D2%3Bteam4_1%3Douhoiunb%3Bresult4_1_0%3D%3Bteam4_2%3D%3Bresult4_2_0%3D%3Bteam6_1%3D%3Bresult6_1_0%3D%3Bteam6_2%3D%3Bresult6_2_0%3D%3Bteam1_1%3D%3Bresult1_1_0%3D%3Bteam1_2%3D%3Bresult1_2_0%3D%3Bteam2_1%3D%3Bresult2_1_0%3D%3Bteam2_2%3D%3Bresult2_2_0%3D%3Bteam5_1%3D%3Bresult5_1_0%3D%3Bteam5_2%3D%3Bresult5_2_0%3D%3Bteam3_1%3D%3Bresult3_1_0%3D%3Bteam3_2%3D%3Bresult3_2_0%3D%3Bteam7_1%3D%3Bresult7_1_0%3D%3Bteam7_2%3D%3Bresult7_2_0%3D%3Bteam9_1%3D%3Bresult9_1_0%3D%3Bteam9_2%3D%3Bresult9_2_0%3D%3Bteam11_1%3D%3Bresult11_1_0%3D%3Bteam11_2%3D%3Bresult11_2_0%3D%3Bteam12_1%3D%3Bresult12_1_0%3D%3Bteam12_2%3D%3Bresult12_2_0%3D%3Bteam8_1%3Dvjgv%2520juxccccc%3Bresult8_1_0%3D%3Bteam8_2%3D%3Bresult8_2_0%3D%3Bteam10_1%3D%3Bresult10_1_0%3D%3Bteam10_2%3D%3Bresult10_2_0%3D%3Bteam13_1%3D%3Bresult13_1_0%3D%3Bteam13_2%3D%3Bresult13_2_0%3D%3B

JavaScript:
<script language="javascript">
 var t = "<?php echo $tourny_title;?>";
 var d = "<?php echo "$tourny_data";?>";
//TITLE, DATE, DATA
readOnlyGame(t ,"2",d );
</script>

The only way it is actually working (with double quotes around last argument):
JavaScript:
<script language="javascript">
readOnlyGame(t ,"2","&teams=8&sets=1&groups=1&modeVal=dko.html&modeTxt=Double%2520Elimination&title=My%2520Tournament%2520Name%252056555&shuffleLooser=true&?data=&matchDetail=11.3.2023%20Double%20Elimination%2C%208%20Teams&matchData=shuffleOrder%253D0.23023348552613987%25252C0.013753975196499457%25252C0.183546196452959%25252C0.18362271900778593%25252C%253Bteam0_1%253Dvjgv%252520ju%253Bresult0_1_0%253D1%253Bteam0_2%253Douhoiunb%253Bresult0_2_0%253D2%253Bteam4_1%253Douhoiunb%253Bresult4_1_0%253D%253Bteam4_2%253D%253Bresult4_2_0%253D%253Bteam6_1%253D%253Bresult6_1_0%253D%253Bteam6_2%253D%253Bresult6_2_0%253D%253Bteam1_1%253D%253Bresult1_1_0%253D%253Bteam1_2%253D%253Bresult1_2_0%253D%253Bteam2_1%253D%253Bresult2_1_0%253D%253Bteam2_2%253D%253Bresult2_2_0%253D%253Bteam5_1%253D%253Bresult5_1_0%253D%253Bteam5_2%253D%253Bresult5_2_0%253D%253Bteam3_1%253D%253Bresult3_1_0%253D%253Bteam3_2%253D%253Bresult3_2_0%253D%253Bteam7_1%253D%253Bresult7_1_0%253D%253Bteam7_2%253D%253Bresult7_2_0%253D%253Bteam9_1%253D%253Bresult9_1_0%253D%253Bteam9_2%253D%253Bresult9_2_0%253D%253Bteam11_1%253D%253Bresult11_1_0%253D%253Bteam11_2%253D%253Bresult11_2_0%253D%253Bteam12_1%253D%253Bresult12_1_0%253D%253Bteam12_2%253D%253Bresult12_2_0%253D%253Bteam8_1%253D%253Bresult8_1_0%253D%253Bteam8_2%253Dvjgv%252520ju%253Bresult8_2_0%253D%253Bteam10_1%253D%253Bresult10_1_0%253D%253Bteam10_2%253D%253Bresult10_2_0%253D%253Bteam13_1%253D%253Bresult13_1_0%253D%253Bteam13_2%253D%253Bresult13_2_0%253D%253B&matchDetail=11.3.2023 Double Elimination, 8 Teams&matchData=shuffleOrder%3D0.21865197396416836%252C0.9990132343964383%252C0.08503560342563254%252C0.5529512381303724%252C0.06779914862511305%252C%3Bteam0_1%3Dvjgv%2520juxccccc%3Bresult0_1_0%3D1%3Bteam0_2%3Douhoiunb%3Bresult0_2_0%3D2%3Bteam4_1%3Douhoiunb%3Bresult4_1_0%3D%3Bteam4_2%3D%3Bresult4_2_0%3D%3Bteam6_1%3D%3Bresult6_1_0%3D%3Bteam6_2%3D%3Bresult6_2_0%3D%3Bteam1_1%3D%3Bresult1_1_0%3D%3Bteam1_2%3D%3Bresult1_2_0%3D%3Bteam2_1%3D%3Bresult2_1_0%3D%3Bteam2_2%3D%3Bresult2_2_0%3D%3Bteam5_1%3D%3Bresult5_1_0%3D%3Bteam5_2%3D%3Bresult5_2_0%3D%3Bteam3_1%3D%3Bresult3_1_0%3D%3Bteam3_2%3D%3Bresult3_2_0%3D%3Bteam7_1%3D%3Bresult7_1_0%3D%3Bteam7_2%3D%3Bresult7_2_0%3D%3Bteam9_1%3D%3Bresult9_1_0%3D%3Bteam9_2%3D%3Bresult9_2_0%3D%3Bteam11_1%3D%3Bresult11_1_0%3D%3Bteam11_2%3D%3Bresult11_2_0%3D%3Bteam12_1%3D%3Bresult12_1_0%3D%3Bteam12_2%3D%3Bresult12_2_0%3D%3Bteam8_1%3Dvjgv%2520juxccccc%3Bresult8_1_0%3D%3Bteam8_2%3D%3Bresult8_2_0%3D%3Bteam10_1%3D%3Bresult10_1_0%3D%3Bteam10_2%3D%3Bresult10_2_0%3D%3Bteam13_1%3D%3Bresult13_1_0%3D%3Bteam13_2%3D%3Bresult13_2_0%3D%3B" );
</script>
 
Joined
Mar 5, 2023
Messages
8
Reaction score
3
It seems that the issue here is that some of the special characters in the `data` parameter are not being properly escaped when passed as a PHP variable.

When you use double quotes around the `data` parameter in your JavaScript function call, you are essentially hardcoding the entire parameter string, including the properly escaped special characters.

To fix this issue, you will need to properly escape the special characters in the `data` parameter before echoing it out as a PHP variable. One way to do this is to use the `urlencode()` function in PHP to properly encode the special characters in the `data` string. Then, when you pass the string to the JavaScript function, you won't need to use double quotes around it, since the special characters will already be properly encoded.

Here's an example of how you could modify your code to properly escape the `data` parameter:

PHP:
<script language="javascript">
  var t = "<?php echo $tourny_title;?>";
  var d = "<?php echo urlencode($tourny_data); ?>";
  readOnlyGame(t ,"2", d);
</script>

With this modification, you should be able to pass the `data` parameter to your JavaScript function without needing to use double quotes around it.
 
Joined
Mar 14, 2023
Messages
8
Reaction score
0
Drogby,

thank you for your repsonse. for some reason it still isnt working.

urlencode:
Code:
%26amp%3Bteams%3D8%26amp%3Bsets%3D1%26amp%3Bgroups%3D1%26amp%3BmodeVal%3Ddko.html%26amp%3BmodeTxt%3DDouble%252520Elimination%26amp%3Btitle%3DMy%252520Tournament%252520Name%25252056555%26amp%3BshuffleLooser%3Dtrue%26amp%3B%3Fdata%3D%26amp%3BmatchDetail%3D11.3.2023%2520Double%2520Elimination%252C%25208%2520Teams%26amp%3BmatchData%3DshuffleOrder%25253D0.23023348552613987%2525252C0.013753975196499457%2525252C0.183546196452959%2525252C0.18362271900778593%2525252C%25253Bteam0_1%25253Dvjgv%25252520ju%25253Bresult0_1_0%25253D1%25253Bteam0_2%25253Douhoiunb%25253Bresult0_2_0%25253D2%25253Bteam4_1%25253Douhoiunb%25253Bresult4_1_0%25253D%25253Bteam4_2%25253D%25253Bresult4_2_0%25253D%25253Bteam6_1%25253D%25253Bresult6_1_0%25253D%25253Bteam6_2%25253D%25253Bresult6_2_0%25253D%25253Bteam1_1%25253D%25253Bresult1_1_0%25253D%25253Bteam1_2%25253D%25253Bresult1_2_0%25253D%25253Bteam2_1%25253D%25253Bresult2_1_0%25253D%25253Bteam2_2%25253D%25253Bresult2_2_0%25253D%25253Bteam5_1%25253D%25253Bresult5_1_0%25253D%25253Bteam5_2%25253D%25253Bresult5_2_0%25253D%25253Bteam3_1%25253D%25253Bresult3_1_0%25253D%25253Bteam3_2%25253D%25253Bresult3_2_0%25253D%25253Bteam7_1%25253D%25253Bresult7_1_0%25253D%25253Bteam7_2%25253D%25253Bresult7_2_0%25253D%25253Bteam9_1%25253D%25253Bresult9_1_0%25253D%25253Bteam9_2%25253D%25253Bresult9_2_0%25253D%25253Bteam11_1%25253D%25253Bresult11_1_0%25253D%25253Bteam11_2%25253D%25253Bresult11_2_0%25253D%25253Bteam12_1%25253D%25253Bresult12_1_0%25253D%25253Bteam12_2%25253D%25253Bresult12_2_0%25253D%25253Bteam8_1%25253D%25253Bresult8_1_0%25253D%25253Bteam8_2%25253Dvjgv%25252520ju%25253Bresult8_2_0%25253D%25253Bteam10_1%25253D%25253Bresult10_1_0%25253D%25253Bteam10_2%25253D%25253Bresult10_2_0%25253D%25253Bteam13_1%25253D%25253Bresult13_1_0%25253D%25253Bteam13_2%25253D%25253Bresult13_2_0%25253D%25253B%26amp%3BmatchDetail%3D11.3.2023%20Double%20Elimination%2C%208%20Teams%26amp%3BmatchData%3DshuffleOrder%253D0.21865197396416836%25252C0.9990132343964383%25252C0.08503560342563254%25252C0.5529512381303724%25252C0.06779914862511305%25252C%253Bteam0_1%253Dvjgv%252520juxccccc%253Bresult0_1_0%253D1%253Bteam0_2%253Douhoiunb%253Bresult0_2_0%253D2%253Bteam4_1%253Douhoiunb%253Bresult4_1_0%253D%253Bteam4_2%253D%253Bresult4_2_0%253D%253Bteam6_1%253D%253Bresult6_1_0%253D%253Bteam6_2%253D%253Bresult6_2_0%253D%253Bteam1_1%253D%253Bresult1_1_0%253D%253Bteam1_2%253D%253Bresult1_2_0%253D%253Bteam2_1%253D%253Bresult2_1_0%253D%253Bteam2_2%253D%253Bresult2_2_0%253D%253Bteam5_1%253D%253Bresult5_1_0%253D%253Bteam5_2%253D%253Bresult5_2_0%253D%253Bteam3_1%253D%253Bresult3_1_0%253D%253Bteam3_2%253D%253Bresult3_2_0%253D%253Bteam7_1%253D%253Bresult7_1_0%253D%253Bteam7_2%253D%253Bresult7_2_0%253D%253Bteam9_1%253D%253Bresult9_1_0%253D%253Bteam9_2%253D%253Bresult9_2_0%253D%253Bteam11_1%253D%253Bresult11_1_0%253D%253Bteam11_2%253D%253Bresult11_2_0%253D%253Bteam12_1%253D%253Bresult12_1_0%253D%253Bteam12_2%253D%253Bresult12_2_0%253D%253Bteam8_1%253Dvjgv%252520juxccccc%253Bresult8_1_0%253D%253Bteam8_2%253D%253Bresult8_2_0%253D%253Bteam10_1%253D%253Bresult10_1_0%253D%253Bteam10_2%253D%253Bresult10_2_0%253D%253Bteam13_1%253D%253Bresult13_1_0%253D%253Bteam13_2%253D%253Bresult13_2_0%253D%253B

and one that works hard coded with double quotes:
Code:
%26teams%3D8%26sets%3D1%26groups%3D1%26modeVal%3Ddko.html%26modeTxt%3DDouble%252520Elimination%26title%3DMy%252520Tournament%252520Name%25252056555%26shuffleLooser%3Dtrue%26%3Fdata%3D%26matchDetail%3D11.3.2023%2520Double%2520Elimination%252C%25208%2520Teams%26matchData%3DshuffleOrder%25253D0.23023348552613987%2525252C0.013753975196499457%2525252C0.183546196452959%2525252C0.18362271900778593%2525252C%25253Bteam0_1%25253Dvjgv%25252520ju%25253Bresult0_1_0%25253D1%25253Bteam0_2%25253Douhoiunb%25253Bresult0_2_0%25253D2%25253Bteam4_1%25253Douhoiunb%25253Bresult4_1_0%25253D%25253Bteam4_2%25253D%25253Bresult4_2_0%25253D%25253Bteam6_1%25253D%25253Bresult6_1_0%25253D%25253Bteam6_2%25253D%25253Bresult6_2_0%25253D%25253Bteam1_1%25253D%25253Bresult1_1_0%25253D%25253Bteam1_2%25253D%25253Bresult1_2_0%25253D%25253Bteam2_1%25253D%25253Bresult2_1_0%25253D%25253Bteam2_2%25253D%25253Bresult2_2_0%25253D%25253Bteam5_1%25253D%25253Bresult5_1_0%25253D%25253Bteam5_2%25253D%25253Bresult5_2_0%25253D%25253Bteam3_1%25253D%25253Bresult3_1_0%25253D%25253Bteam3_2%25253D%25253Bresult3_2_0%25253D%25253Bteam7_1%25253D%25253Bresult7_1_0%25253D%25253Bteam7_2%25253D%25253Bresult7_2_0%25253D%25253Bteam9_1%25253D%25253Bresult9_1_0%25253D%25253Bteam9_2%25253D%25253Bresult9_2_0%25253D%25253Bteam11_1%25253D%25253Bresult11_1_0%25253D%25253Bteam11_2%25253D%25253Bresult11_2_0%25253D%25253Bteam12_1%25253D%25253Bresult12_1_0%25253D%25253Bteam12_2%25253D%25253Bresult12_2_0%25253D%25253Bteam8_1%25253D%25253Bresult8_1_0%25253D%25253Bteam8_2%25253Dvjgv%25252520ju%25253Bresult8_2_0%25253D%25253Bteam10_1%25253D%25253Bresult10_1_0%25253D%25253Bteam10_2%25253D%25253Bresult10_2_0%25253D%25253Bteam13_1%25253D%25253Bresult13_1_0%25253D%25253Bteam13_2%25253D%25253Bresult13_2_0%25253D%25253B%26matchDetail%3D11.3.2023%20Double%20Elimination%2C%208%20Teams%26matchData%3DshuffleOrder%253D0.21865197396416836%25252C0.9990132343964383%25252C0.08503560342563254%25252C0.5529512381303724%25252C0.06779914862511305%25252C%253Bteam0_1%253Dvjgv%252520juxccccc%253Bresult0_1_0%253D1%253Bteam0_2%253Douhoiunb%253Bresult0_2_0%253D2%253Bteam4_1%253Douhoiunb%253Bresult4_1_0%253D%253Bteam4_2%253D%253Bresult4_2_0%253D%253Bteam6_1%253D%253Bresult6_1_0%253D%253Bteam6_2%253D%253Bresult6_2_0%253D%253Bteam1_1%253D%253Bresult1_1_0%253D%253Bteam1_2%253D%253Bresult1_2_0%253D%253Bteam2_1%253D%253Bresult2_1_0%253D%253Bteam2_2%253D%253Bresult2_2_0%253D%253Bteam5_1%253D%253Bresult5_1_0%253D%253Bteam5_2%253D%253Bresult5_2_0%253D%253Bteam3_1%253D%253Bresult3_1_0%253D%253Bteam3_2%253D%253Bresult3_2_0%253D%253Bteam7_1%253D%253Bresult7_1_0%253D%253Bteam7_2%253D%253Bresult7_2_0%253D%253Bteam9_1%253D%253Bresult9_1_0%253D%253Bteam9_2%253D%253Bresult9_2_0%253D%253Bteam11_1%253D%253Bresult11_1_0%253D%253Bteam11_2%253D%253Bresult11_2_0%253D%253Bteam12_1%253D%253Bresult12_1_0%253D%253Bteam12_2%253D%253Bresult12_2_0%253D%253Bteam8_1%253Dvjgv%252520juxccccc%253Bresult8_1_0%253D%253Bteam8_2%253D%253Bresult8_2_0%253D%253Bteam10_1%253D%253Bresult10_1_0%253D%253Bteam10_2%253D%253Bresult10_2_0%253D%253Bteam13_1%253D%253Bresult13_1_0%253D%253Bteam13_2%253D%253Bresult13_2_0%253D%253B
 
Joined
Mar 14, 2023
Messages
8
Reaction score
0
i was able to make a change the way i needed it doing this:


JavaScript:
var d = "<?php echo $tourny_data1;?>";
var textarea =escape(d);
var find = ["%26amp%3B", "%3D8%26amp%3B"];
var replace = ["%26", "%3D8%26"];
textarea = textarea.replaceArray(find, replace);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top