Missing + (plus) symbol with GET method

Hi everyone,
I have come across a very interesting situation. Suppose in one php file I have a variable that holds a value as Na with a plus symbol as superscript on the right-up corner as it is a Chemistry symbol of an entity called “ion”. Situation is this. The symbol is present in mysql table. I get it to be shown to the user. User submits the answer based on his choices. Upon submit I get the values of boxes using the Javascript. No issue even with the Javascript as I have tested it. Now when I pass the value using a javascript variable to other php file for further processing using GET method I miss the + symble at the receiving file. The value I am passing using any variable is “Na+” excluding the double quotations. But the receiving php file shows me only "Na " with missing + symbol. Please Help!

Can you encode it as
+
+

Thanks for your reply. I tried but again this does not work. I think, the issue remains same. This way before send the option to the other php file the current php file converts this code into the + sign then sends it.

whats your javascript code look like? i’m suspecting that it’s not getting the value as you expect.

x1 = document.getElementById(“trag1”).innerHTML;
x2 = document.getElementById(“qtrag1”).innerHTML;

x=x1+‘z’+x2;
window.document.location.href = “exam6.php?cct2=”+x;

And when it loads, do you see the superscript X in the URL bar?

The issue is, I am using the Na with a plus sign on the right side for Sodium ion. The javascript is reading the rendered code, not the code values but rendered one as Na+ . I have checked it with javascript. It takes the value properly. When I send it, it does not reach at the receiving php file. Interenstingly a - sign prefixed with other option value is reaching properly. But this postfix type of plust that is used in above ion’s name is causing problem.

You didnt answer my question. Do you see the symbol in the URL when the page is force-reloaded by window.document.location.href?

Yes I can see the plus sign with the sup tags as well

Yes I can see the + sign in the URL at the receiving file.

K. So javascript is not URLEncoding the data. Run your strings through encodeURIComponent().

Mittineague was close, but you dont want to use & based encodings for URL query strings because it thinks you’re defining a second variable. We want the percent-symbol representation of the character.

(NOTE: This character is UTF-8 based)

The URL string should look something like Na%E2%81%BA

http://127.0.0.1/phpfiles2/exam6.php?cct2=<strong>C<sup>12</sup></strong>**z**Avogadro%20Number**z**Indeterminate**z**Atomic%20Mass**z**Ion**z**Random**z**<strong>Na<sup>+</sup></strong>**z**Mole

sorry the code is bit lengthy. I am also using z (double asterisk on each side of z as delimiter)
I have noticed it is present in the URL but at the receiving I am just echo (ing) it and it is not happeneing

Ahhh i see what you’re doing now.

You’re not actually putting the superscript + SYMBOL in there, you’re making it using HTML elements.
Well, the script doesnt need those bits. Let’s clean it up.

.replace(/(<([^>]+)>)/ig,“”) on your strings before urlencoding them. That should leave you with something a lot more readable.

(I am not a javascript guru - there’s probably a better way to effect a strip_tags, but someone else will have to show me up on that one ;))

I did not get this. But can you do me a favour. Just tell me how to send Na+ to the other php file that receives it properly. Because i can see at the receiving url and it shows me perfectly sup + /sup and when I just use the echo cct2 (cct2 is the name of the variable) it does not just the + sign of superscript only the Na is shown.

So my version (untested) is:
x1 = encodeURIComponent(document.getElementById(“trag1”).innerHTML.replace(/(<([^>]+)>)/ig,“”));

This should reduce your URL string to cct2=2zAvogadro%20NumberzIndeterminatezAtomic%20MassxIonzRandomzNa%2BzMole

Which you can then parse with PHP.

Many thanks.
It really works.

Best Regards
:smiley:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.