Populating a text box in a website using javascript

I am working on a project that I will need to populate a textbox inside BMC Web Remedy with information with a JavaScript / HTA file. - Essentially I just need to click text in the text box on the site

I can't figure out how to fill out this information on the page itself, although I wondered if I could get some guidance if possible / how I would go about doing this, or just pointed to the right direction.

Just explain as an example on the website: http://www.brivers.com/resume/scripts/tutorial-hta-textbox.php

Entering data in the name / address / city field

Something like this, only I'm not sure how to move it to a website field

** Sorry, just to clarify the field I want to push is an external application, is there a way to push it to a text field on (literally any) website? e.g. username / password textbox on any site

<script language="javascript" type="text/javascript">
function PushData_NSO(){
var userinput = txtPhoneNum.value;
document.getElementById('txtName').value = userinput;
}
</script>


<body>
<p> <input id="txtPhoneNum" type="text" value=""> </p>
<p> <input type="button" onclick="PushData_NSO()"> </p>
</body>

      

+3


source to share


6 answers


You are trying to do getElementById('txtName')

where html <input id="txtPhoneNum" />

. This will never work because it is id

not the same as the one you are trying to access.

For errors like this, you can use developer tools (Chrome, IE, Firefox shortcut F12

) to see if there are errors in the console.



Also, the variable txtPhoneNum

is undefined. If you want it to be an element input

, you must do it first txtPhoneNum = document.getElementById('txtPhoneNum')

.

I created a plunker to illustrate.

+1


source


Please try the following:



<script language="javascript" type="text/javascript">
  function PushData_NSO(){

      //First get the value or text, for an instance, just say "sampleText".
       var userinput = document.getElementById('txtPhoneNum').value;


      //Secondly get the id of the textbox and using that append the value to that textbox.
       document.getElementById('txtName').value = userinput;
  }
</script>

      

0


source


Get data from HTML, for example

var userinput = document.getElementById('txtPhoneNum').value;
// do something with userinput

      

To display data in HTML you must use

document.getElementById("whateverID").innerHTML = "changed user input"; 

      

0


source


try this:

<script type="text/javascript">

function PushData_NSO(){
var userinput = document.getElementById('txtPhoneNum').value;
document.getElementById('txtName').value = userinput;
}
</script>


<body>
<p> <input id="txtPhoneNum" type="text" value=""> </p>
  <input type="text" id="txtName" value="" />

<input type="button" onclick="PushData_NSO()" value="push "/>
</body>

      

0


source


When you use getElementById ('ValueOfID') javascript looks for all elements in the html where the id attribute has the same value as the ValueOfID (in this case).

... The value after getElementById means that you are going to do something with that value, in which case you change it to whatever is in the userinput variable.

So, in your case, you need to do:

<script language="javascript" type="text/javascript">
function PushData_NSO(){
var userinput = txtPhoneNum.value;
document.getElementById('txtPhoneNum').value = userinput;
}
</script>

      

0


source


I think this is what you are after

<form>
    <input id="txtPhoneNum" type="text" value=""/>
    <input type="button" onclick="PushData_NSO()" value="Add Number to Div"/>
</form>
<br/>
<div id="txt">The number will replace this text</div>

<script>
function PushData_NSO(){
    var userinput = document.getElementById('txtPhoneNum').value
    document.getElementById('txt').innerHTML = userinput;
}
</script>

      

Here is the JSFIDDLE showing it in action, if you have any questions about this feel free to ask

0


source







All Articles