PDA

View Full Version : Passing a value from html to JavaScript


ipquix
10-03-01, 01:10 PM
I'm taking a class called internet programming and in it is a one month section of JavaScript. The only other language I've ever had was apple basic way back in junior high, so this is very very different. I am having trouble figuring out how to pass the value from my form in the html code to the function in the JavaScript. I've read the book, and there seems to be a million different ways to do it. Does anyone have any advice?

ipquix
10-03-01, 01:25 PM
Here is an example. This is a simple program that /should/ work, everything I've read says it should work, all the examples I looked at say it should work, but the function still isn't getting the value, what am I doing wrong?

<html>
<head>
<title>Personalized Greeting</title>
<script language="JavaScript1.2">
<!-- hide from older browsers
function greet(hello)
{
if(hello == "y")
{
name=prompt("Please enter your name", "Enter your name here");
alert("Welcome "+name+"!");
}
else
{
alert("Welcome guest!");
}
}

// Stop hiding -->
</script>
</head>
<body>
<FORM NAME="Welcome">
Would you like to see a personalized greeting?<br>
<INPUT TYPE=radio NAME="yesOrNo" VALUE="y"
onClick="greet(this.value)">Yes<BR>
<INPUT TYPE=radio NAME="yesOrNo" VLAUE="n"
onClick="greet(this.value)">No<BR>
</FORM>
</body>
</html>

Thelemac
10-04-01, 04:57 AM
Originally posted by ipquix
<html>
<head>
<title>Personalized Greeting</title>
<script language="JavaScript1.2">
<!-- hide from older browsers
function greet(hello)
{
if(hello == "y")
{
name=prompt("Please enter your name", "Enter your name here");
alert("Welcome "+name+"!");
}
else
{
alert("Welcome guest!");
}
}

// Stop hiding -->
</script>
</head>
<body>
<FORM NAME="Welcome">
Would you like to see a personalized greeting?<br>
<INPUT TYPE=radio NAME="yesOrNo" VALUE="y"
onClick="greet(this.value)">Yes<BR>
<INPUT TYPE=radio NAME="yesOrNo" VLAUE="n"
onClick="greet(this.value)">No<BR>
</FORM>
</body>
</html>

If you cut and pasted this code, then the part in bold is your problem, or at least part of it. Possilby also the caps. Not sure if Javascript is caps sensitive or not, but most languages are.