Forum Moderators: open
I'm having a devil of a time trying to grab a value from my form and running it in a script.
I've simplified my form, and posted it below. Any ideas? Anybody see my typo or problem? Right now, the alert comes back undefined.
Thanks
------
<html>
<head>
<script type="text/javascript" language="javascript">
var TestVar = document.q.q101.value;
function check(){alert(TestVar);return false;}
</script>
</head>
<body>
<form method="post" id="q" name="q" onSubmit="return check()">
<input type="radio" name="q101" value="y"><input type="radio" name="q101" value="n">
<button type="submit">Next</button>
</form>
</body>
</html>
<html>
<head>
<script type="text/javascript" language="javascript">
function check(which){
var TestVar = which.q101.value;
alert(TestVar);
return false;
}
</script>
</head>
<body>
<form method="post" id="q" name="q" onSubmit="return check(this)">
<input type="radio" name="q101" value="y"><input type="radio" name="q101" value="n">
<button type="submit">Next</button>
</form>
</body>
</html>
I didn't realize the value was being defined right away, I thought since it didn't run until on pressed the submit button, that it would work.
I tried using the modified script you provided, but I still had issues with it. I do not totally understand values in the parentheses, so I don't know if I have to change it from what was provided. (ie; do I use check(which) and check(this), or something else?)
Thanks