<script stylesheet="text/javascript">
var statename;
function confirmReview(formObj){
function myState( val ){
statename = val;
alert( "This is " + statename );
}
postcode = document.getElementById("postcode");
//Folowing code
if( statename== "Selangor" ){
if( postcode < 10000 || postcode > 40000 )
alert( "Invalid postcode for " + statename );
}
}
</script>
<body>
<form name = reviewform onsubmit="return confirmReview(reviewform)" method=POST>
<select id='state' onchange="myState(this.value);">
<option>Specify state or territory</option>
<option value="Selangor">Selangor</option>
<option value="Terengganu">Terengganu</option>
</select>
</form>
</body>
my question is how to store the value and save it to the statename as i fail to run in my HTML javascript code. can anyone teach?
i cannot print out my statename example if i want to make some comparison for my postcode when i load the script it run to the funciton . my HTML will just clear all the data like refresh the page without showing anything
after i edited the things senior suggested . it's still same. it cannot go to the alert that validation code with the statename