0

So my question is, how do I pass variables to javascript functions through html input boxes?

Like, let's say I have a function:

function Call(number, text, callerID, CallerIDName, PassCode)

How would I make an input box in html so that when the user submits a value into the box, it would set the variable for that corresponding box?

All help is appreciated, thanks!

  • 1
    This is a bit unclear...from what I can tell, you just have to call a function with the current value of the box, something like `onblur='myFunc(this.value)'` – tymeJV Dec 06 '13 at 19:57
  • That depends entirely upon where those variables are coming from. What's your (relevant) html? – David Thomas Dec 06 '13 at 19:57
  • Can you give me some example code of how I would pass an input box value to a javascript function? That is what I'm asking. @DavidThomas that's what I'm asking, how do I put them in through html input boxes? I'm not trying to complicate things here. I am asking simply how do I pass javascript function variables through html input boxes? –  Dec 06 '13 at 19:58

2 Answers2

0

Let's say you have an input tag for the "number" parameter:

<input type="text" id="number" />

You can then obtain the value of the field like this;

document.getElementById("number").value

You can find a few examples here. Let me know if I misunderstood your question.

Henrik
  • 444
  • 4
  • 14
  • Okay, this is good, but how would I go about adding a submit button beside it so that it only processes that specific value when that button is clicked? –  Dec 06 '13 at 20:05
  • So, you want to trigger the Call Javascript function when the submit button is pressed, and do something with the values in the input fields? – Henrik Dec 06 '13 at 20:09
0

Try something like this...

    Name: <input type="text" id="number"><br>
    Text: <input type="text" id="text"><br>
    Caller Id Name: <input type="text" id="CallerIDName"><br>
    Passcode: <input type="text" id="Passcode"><br>
    <script>
    function Call() {
        var number = document.getElementById("number").value;
        var text = document.getElementById("text").value;
        var CallerIDName = document.getElementById("CallerIDName").value;
        var Passcode = document.getElementById("Passcode").value;
        //do something here...
    }
    </script>
    <button onclick="Call();">Click to Call</button>
Bobby Russell
  • 475
  • 2
  • 12