I recently received help on this site towards using querySelector
on a form input such as select
but as soon as I took <select>
out it completely changed what had to be done in the function.
HTML:
<form onsubmit="return checkForm()">
Password: <input type="text" name="pwd">
<input type="submit" value="Submit">
</form>
Javascript:
<script language="Javascript" type="text/javascript">
debugger;
function checkForm() {
var form = document.forms[0];
var selectElement = form.querySelector('');
var selectedValue = selectElement.value;
alert(selectedValue);
</script>
Before, I had ('select')
for the querySelector
, but now I'm unsure what to put there.
I've tried multiple things as well as querySelectorAll
but I can't seem to figure it out.
To be clear I'm trying to pull the name="pwd"
.
How could I do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…