-1

I would like to create an alert that passes in information typed in by the user.

<button type="button" onclick="alert('Hello')">Click Me!</button>''''

but instead of "hello" information from a form

<input type='text' maxlength="25" id='first-name' placeholder="First Name">
<script>
var Variablez = document.getElementById('first-name').innerText;
</script>
<button type="button" onclick="alert(Variablez)">Click Me!</button>''''
aaron lilly
  • 274
  • 1
  • 14

2 Answers2

1

All you have to do is restructure your script. Don't use inline for this case, give your button an id and you can set the onclick event in your script.

<input type='text' maxlength="25" id='first-name' placeholder="First Name">
<button id="btn" type="button" onclick="alert(Variablez)">Click Me!</button>

<script>
var btn = document.getElementById('btn');
btn.onclick = function() {
    var Variablez = document.getElementById('first-name').value;
    alert(Variablez);
};
</script>
Ibu
  • 42,752
  • 13
  • 76
  • 103
0

this works , just make sure jquery is plugged in

<div>
<input type='text' maxlength="25" id='first-name' placeholder="First Name">
</div>

<button type="button" onclick="alert($('#first-name').val())">Click Me!     </button>
aaron lilly
  • 274
  • 1
  • 14