Ralph Schipper
Ralph Schipper

Reputation: 741

how do I put some text between the a href taggs?

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>

Upvotes: 0

Views: 76

Answers (3)

DerStrom8
DerStrom8

Reputation: 1341

var phoneNum = document.getElementById('number');
phoneNum.innerHTML=("Call " + phoneNumberToCall); //Could also use phoneNum.innerText

Upvotes: 0

bjb568
bjb568

Reputation: 11488

Use element.textContent:

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

innerText is an IE thing.

Upvotes: 1

Barmar
Barmar

Reputation: 780714

Set the innerText property of the element.

output.innerText = "Call "+nummer;

Upvotes: 3

Related Questions