GetElement by id

Hello,

I don’t understand why it’s not working ?

I don’t find anything about that on google or stackoverflow that explain my problem.

function register(username, password, email) { var routes = [ { id: "register", name: "Shop 1", value: 'http://localhost:5000/register', },
{
	id: "login",
	name: "Shop 2",
  value: 'http://localhost:5000/register',
},

];

var niceRoute;
niceRoute = routes.getElementById(‘register’).value;

the error i got is : JS stack trace: TypeError: routes.getElementById is not a function

You can use Observables to get access to the variables in your Javascript

View

<StackPanel>
    <TextInput PlaceholderText="Email" Value="{email}" />
    <TextInput PlaceholderText="Password" Value="{password}" IsPassword="true" />
    <Button Text="Submit"  Clicked="{login}" />
</StackPanel>

JS

var Observable = require('FuseJS/Observable');
var email = Observable('');
var password = Observable('');

function login(){
   //here you can use the variables email and password....
   var loginEmail = email.value;
   var loginPassword = password.value;
}

module.exports = {
	email: email,
	password: password,
};

Thanks for your awnser.

But everyhting is happing in a JS file.

I have an array of string (id , name ). And I want to get an element in the same file to use it in my function. (the value field)

Because when I call the function, the value value: “‘http://localhost:5000/register’” might change depending on the button I clicked.

As an example : I call the function with “login” as argument , so I get in the array the element with id “login” so i can use the URL corresponding.

Please can you be more specific. If possible some codes ? would help figure out the issue

yes, I will post all the file, but how the "< code > balise works ? , I got something like that :

function register(username, password, email)
{

  var routes = [
  	{
  		id: "register",
  		name: "Shop 1",
  		value: 'http://localhost:5000/register',
  	},
  	{
  		id: "login",
  		name: "Shop 2",
      value: 'http://localhost:5000/register',
  	},
  ];

  var niceRoute;

  niceRoute = routes.getElementById('register').value;
         nice = niceRoute.value;

console.log("value URL = " + nice);

  fetch(nice, {
    method: 'post',
    headers: { "Content-type": "application/json"},
    body: JSON.stringify({
      username: username.value,
      password: password.value,
      email: email.value,
    })
  }).then(function(response) {
    status = response.status;
    response_ok = response.ok;
    return response.json();
  }).then(function(responseObject) {
    console.log("Reponse : " + responseObject.username);
    data.value = responseObject;
  }).catch(function(err) {
    console.log("error : " + err);
      // An error occurred somewhere in the Promise chain
    });
}

I found one way to do it :

function Communicate(url, body)
{

  for (var i = 0; i < routes.length; i++) {
                  var good = routes[i];
                  if (good.id == url) {
                    break;
                  }
              }


  fetch(good.value, {
    method: 'post',
    headers: { "Content-type": "application/json"},
    body: body
  }).then(function(response) {
    status = response.status;
    response_ok = response.ok;
    return response.json();
  }).then(function(responseObject) {
    console.log("Reponse : " + responseObject.username);
    data.value = responseObject;
  }).catch(function(err) {
    console.log("error : " + err);
      // An error occurred somewhere in the Promise chain
    });
}

Even if this is working, I still don’t understand why I couldn’t use GetElementById on this array.

Thanks for the help @quincykwende

to get the code view working use 3 of `
3 above code and 3 below code

Check here: https://help.github.com/articles/basic-writing-and-formatting-syntax/

I have updated my post above

This is a javascript issue not Fuse. If you need to get element from the Object don’t use getElementById here. you have no HTML ID here

var routes = [ { id: "register", name: "Shop 1", value: 'http://localhost:5000/register', }, 
{ id: "login", name: "Shop 2", value: 'http://localhost:5000/register', }, ];

//if you want to get items in the first array of this object to as follows
var id = routes[0].id;  // stores 'register'
var name = routes[0].name; //stores Shop 1
var value = routes[0].value; //stores http://localhost:5000/register

//for the second
var id_2 = routes[1].id;  // stores 'login'
var name_2 = routes[1].name; //stores Shop 2
var value_2 = routes[1].value; //stores http://localhost:5000/register

If I understand your question properly. This will sort it out

Thank you for the awnser.

Not used to javascript , I like fuse thought

Cleaner option you have — since the object might have more than 2 items. Also you can make it an associative array.

So don’t use getElement here — This is use to get a value from HTML.

amade.gabriel@gmail.com wrote:

Thank you for the awnser.

Not used to javascript , I like fuse thought

I guest your problem is solved