1

I am new to web development . I have a question I am trying to build a website that takes input on the front end from the HTML page and actively changes the value on the backend javascript file . The functions I have on the backend rely on the front end input . The input never changes it just stays the default value "google.com". For Reference here is some code of what I am trying to accomplish .

HTML WebPage

<input type="text"  id="input" value="google.com" placeholder="somewebsite.com">

Backend JavaScript File

var ajaxWebSiteValue = document.getElementById("input");

function getURL(){
    var URL = "http://" + ajaxWebSiteValue.value ;
    return URL;
}
1
  • what do you mean by " actively changes the value", of what you are trying to change the value? Commented Jun 2, 2020 at 18:36

2 Answers 2

1

It not clear what exactly you want to achieve here because heading, description and code snippet looks contradictory to each other.

1.If you are changing the input value on UI but not getting updated value in backend then use

function getURL(){
     var ajaxWebSiteValue = document.getElementById("input");
     var URL = "http://" + ajaxWebSiteValue.value ;
     return URL;
}

2.If you want to change the value of input from backend.

function getURL(){
     var ajaxWebSiteValue = document.getElementById("input");
     ajaxWebSiteValue.value  = "http://" + ajaxWebSiteValue.value ;
}

Also make sure that you are calling getURL() function from somewhere.

Sign up to request clarification or add additional context in comments.

Comments

0

is that is what you want to achive??

var ajaxWebSiteValue;

function myFunction(){
  ajaxWebSiteValue = document.getElementById('input').value;

document.getElementById("ajaxWebSiteValue").innerText = ajaxWebSiteValue;

document.getElementById("returnedURL").innerText = getURL();
}

function getURL(){
    var URL = "http://" + ajaxWebSiteValue;
    return URL;
}
<input type="text"  id="input" value="google.com" placeholder="somewebsite.com" />

<p id="ajaxWebSiteValue"></p>

<p id="returnedURL"></p>

<button id="change" onclick="myFunction()">change</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.