Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass boolean variable of false in a URL

Tags:

html

get

I cannot work out how to pass a variable with a boolean value of false through a URL string. What is the correct method?

  • domain/page?test=false
  • domain/page?test=
  • domain/page?test=0
like image 399
Benjen Avatar asked Apr 20 '15 05:04

Benjen


People also ask

What is the Boolean value of false in JavaScript?

The Boolean value of "" (empty string) is false: The Boolean value of false is (you guessed it) false: Do not create Boolean objects. The new keyword complicates the code and slows down execution speed. Note the difference between (x==y) and (x===y). (x == y) true of false? (x === y) true of false?

How do you check if a variable is true or false?

TRUE / FALSE; For this, JavaScript has a Boolean data type. It can only take the values true or false. The Boolean() Function. You can use the Boolean() function to find out if an expression (or a variable) is true: Example. Boolean(10 > 9) // returns true

Why does JavaScript have a Boolean data type?

Very often, in programming, you will need a data type that can only have one of two values, like For this, JavaScript has a Boolean data type. It can only take the values true or false.

How to use Boolean in Bash?

Bash does not support Boolean values, but any bash variable can contain 0 or “ true ” and 1 or “ false “. The logical boolean operators are supported by bash.


2 Answers

URLs are strings and all values in a URL are strings. When you see i=0 in a URL, 0 is a string. When you see b=true, true is a string. When you see s=, the value is an empty string.

For those strings to take on another meaning—the integer 0 or the Boolean true, say—the server-side program must be told how to interpret them. Often web frameworks will make intelligent guesses as to the right type, or sometimes a type is declared explicitly in a model.

How you'll do it depends entirely on what server-side language and what framework, if any, you're using.

like image 125
Jordan Running Avatar answered Oct 07 '22 20:10

Jordan Running


Like mentioned above, it's depends on the server-side language you are using as to how you will handle it. To add to the answer, if you want to pass a true or false in the URL as a parameter you can

running node on server

const whatever = JSON.parse(queryStringParameter)

running php on server

$whatever = json_decode(queryStringParameter)

Both options will give you a boolean type that you can use on the server.

like image 31
brandon-estrella-dev Avatar answered Oct 07 '22 20:10

brandon-estrella-dev