Это можно сделать несколькими способами.
Пример 1 { // передача значений с использованием аргументов / параметров
<script>
function showme(answer) {
alert("You said your name is " + answer + "!");
doSomething(answer);
}
function doSomething(name) {
alert("Second function called with the name \"" + name + "\".");
}
</script>
<button onclick="showme(prompt('What\'s your name?'));">Click here</button>
}
Пример 2 { // Использование глобальных переменных
<script>
var name = "";
function setName(answer) {
// Set the global variable "name" to the answer given in the prompt
name = answer;
// Call the second function, without having to pass any params
showName();
}
function showName() {
alert("You said your name was " + name ".");
}
</script>
<button onclick="setName(prompt('What\'s your name?'));">Click here</button>
}
Пример 3 { // Простой метод
<script>
var name = "";
function setName(answer) {
// Set the global variable "name" to the answer given in the prompt
name = prompt('What\'s your name?');
// Call the second function, without having to pass any params
showName();
}
function showName() {
alert("You said your name was " + name ".");
}
</script>
<button onclick="setName();">Click here</button>
}