0

I'm new to javascript I've created this code and it almost works. The href works but how do I put the fixed phonenumber between the a href taggs?

document.write does not work.

Any ideas?

<!DOCTYPE HTML>
<html>
<head>
    <title>test</title>
</head>
<body>
    <script type="text/javascript">
        function fix(nummer) {
            var nieuw = nummer.replace(/\D/g,'');
            var output = document.getElementById("nummer");
            var href = 'http://10.0.1.151/?call=' + nieuw;
            output.setAttribute("href", href);
            output.document.write(nieuw);
        }
    </script>
    <label>Typ telefoonummer</label><input id="telefoon" style="margin-left: 30px" type="text" onblur="fix(this.value)" />
    <span><a target="_blank" id="nummer">Call [how do I get the fixed number here??]</a></span>
</body>
</html>
Filburt
  • 17,626
  • 12
  • 64
  • 115
Ralph Schipper
  • 701
  • 2
  • 12
  • 24

3 Answers3

3

Set the innerText property of the element.

output.innerText = "Call "+nummer;
Barmar
  • 741,623
  • 53
  • 500
  • 612
1

Use element.textContent:

document.getElementById('nummer').textContent = "Call " + nummer;

innerText is an IE thing.

Community
  • 1
  • 1
bjb568
  • 11,089
  • 11
  • 50
  • 71
0
var phoneNum = document.getElementById('number');
phoneNum.innerHTML=("Call " + phoneNumberToCall); //Could also use phoneNum.innerText
DerStrom8
  • 1,311
  • 2
  • 23
  • 45