Louko
Louko

Reputation: 33

Populating Textbox on website using javascript

I am working on a project that i would need to populate textbox's inside of BMC Web Remedy with information with JavaScript/HTA File. -- Essentially I just need to Push text into textbox's on the site

I can't seem to figure out how to populate the information onto the page itself though, was wondering if I could get some guidance of if this is possible/how i would go about doing this, or just pointed in the right direction.

Just to clarify as an example on the web site: http://www.brivers.com/resume/scripts/tutorial-hta-textbox.php

Having data push into the name/address/city field

Something like this only I'm not sure how to push it to the website field itself

**sorry just to clarify the field I am wanting to push this to is external of the application, is there a way to push this to a text field on (literally any) website? for example a 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>

Upvotes: 3

Views: 4587

Answers (6)

akaBase
akaBase

Reputation: 2250

I think this is what your 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 a JSFIDDLE showing it in action, if you have any questions about this feel free to ask

Upvotes: 0

Nayana_Das
Nayana_Das

Reputation: 1817

Please try this:

<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>

Upvotes: 0

NickGames
NickGames

Reputation: 312

When you use getElementById('ValueOfID'), the javascript searches all the elements in the html where the id attribute is the same value as "ValueOfID" (in this case).

The .value after getElementById means you are going to do something with that value, in this 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>

Upvotes: 0

Highmastdon
Highmastdon

Reputation: 7530

You're trying to do getElementById('txtName') where the html is <input id="txtPhoneNum" />. This will never work because the id isn't the same as the one you're trying to access.

For errors like this, you could use the developer tools (Chrome, IE, Firefox shortcut F12) to see if there are errors in the console.

Furthermore the variable txtPhoneNum isn't defined. If you'd want it to be the input-element you should first do txtPhoneNum = document.getElementById('txtPhoneNum').

I've created a plunker to illustrate.

Upvotes: 1

Suchit kumar
Suchit kumar

Reputation: 11869

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>

Upvotes: 0

kmario23
kmario23

Reputation: 61485

Get the data from HTML like this,

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

To display data in HTML you should use,

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

Upvotes: 0

Related Questions