wixLocation.query is returning empty string

I have added this code to a form, but it keeps comimg back empty.

This works fine - orderNumber is shows “This is a Test”:

$w . onReady ( function () {
$w ( ‘#orderNumber’ ). value = “This is a Test”
})

This works fine - orderNumber shows my base url :

import wixLocation from ‘wix-location’ ;
$w . onReady ( function () {
$w ( ‘#orderNumber’ ). value = wixLocation . baseUrl
})

This fails and seems to return an empty string even though my url ends with ?orderNumber=12345

import wixLocation from ‘wix-location’ ;
$w . onReady ( function () {
$w ( ‘#orderNumber’ ). value = wixLocation .query
})

This works, but I don’t know why. I guess I don’t understand the query objejct.

import wixLocation from ‘wix-location’ ;
$w . onReady ( function (){
$w ( ‘#orderNumber’ ). value = wixLocation .query
})

Not sure why that works either. Try inspecting the result with a console.log() statement, like this:

$w.onReady(function(){
   console.log(wixLocation.query);
   $w('#orderNumber').value = wixLocation.query
})

You will see in the console, that wixLocation.query is an object, and not a string. It probably looks something like this:

{ "orderNumber": "12345" }

The value property of the #orderNumber element is a string. So, what you need is more like this:

$w.onReady(function(){
   console.log(wixLocation.query.orderNumber);
   $w('#orderNumber').value = wixLocation.query.orderNumber;
})

See the wix-location.query API for details.