Hello guys, how can I set variable firstName equal to getElementById?
I have this:
<script type="text/javascript">
var firstName = *this have to be set equal to getelementbyid(firstName).value*
function nameCheck(){
if(firstName=="Bas"){
alert("Welcome Bas!")
}else{
alert("Welcome somebody else than Bas!")
}
}
</script>
<input type="text" id="firstName">
<input type="submit" value="submit name" onClick="nameCheck()">
I'm using html... not php (I just wanna be sure you know ;-) )
bacterial vaginosis
Sponsored by: █ Sparkhost - Hosting Without Compromises! █ Hybrid Performance Web Hosting █ Spark Host Stream Hosting █ Hybrid IRC & IRCd Server Shell Accounts
Javascript Set A Variable Equal To Getelementbyid?
Started by
varislost555
, Jun 23 2012 12:35 AM
1 reply to this topic
#1
Posted 23 June 2012 - 12:35 AM
#2
Posted 24 June 2012 - 02:27 AM
<input type="text" id="firstName">
<input type="submit" value="submit name" onClick="nameCheck()"> <!-- It's not c00l to use inline JS, it's way better to use addEventListener & attachEvent -->
<script type="text/javascript">
var firstName // Instead of declaring the var here, I would rather declare it in the scope of nameCheck
, nameCheck = function() {
firstName = document.getElementById('firstName').value;
(firstName == 'Bas') ? alert('Welcome Bas!') : alert('Welcome somebody else than Bas!');
}
;
</script>
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users












