PDA

View Full Version : alert message if selection is selected


florida
01-31-2003, 08:20 PM
I have a form that I want to pop up an alert message is someone selects the letter "A" from my select menu. I tried all different stuff and cant get the alert message to pop up when "A" is selected. I tried :
if(document.myform.myvalue.value = "A")

and it popped up alert message on all selections.

Here is the whole form part where I tried:


function check()
{
msg=''

if(document.myform.myvalue.value == "A")
{
alert("Dont select the letter A")
return false

}



<cfform name="myform" action="dosomething.cfm" onSubmit="return check();">


<select name="myvalue" size="1">
<option value="A" selected>A</option>
<option value="b">b</option>
<option value="c">c</option>


</select>

Danne
01-31-2003, 08:27 PM
I don't know what that doSomething.cfm is but this code works for me:


<script language="JavaScript">

function check()
{
msg=''

if(document.myform.myvalue.value == "A")
{
alert("Dont select the letter A")
return false

}
}

</script>
<form name="myform" action="newPage.html" onSubmit="return check();">
<select name="myvalue" size="1">
<option value="A" selected>A</option>
<option value="b">b</option>
<option value="c">c</option>
</select>

<input type="submit">
</form>

joeframbach
01-31-2003, 08:28 PM
if(document.myform.myvalue.A.checked == true)

Jimbo
01-31-2003, 08:35 PM
<head>
<title>Untitled</title>
<script langauge="text/javascript">
<!--
function check()
{
msg=''

if(document.myform.myvalue.options[document.myform.myvalue.selectedIndex].value == "A")
{
alert("Dont select the letter A")
return false
}
}
-->
</script>
</head>

<body>



<form name="myform" action="dosomething.cfm" onSubmit="return check();">


<select name="myvalue" size="1">
<option value="A" selected>A</option>
<option value="b">b</option>
<option value="c">c</option>
<input type="submit" value="submit">

</select>
</form>
</body>


:)

florida
01-31-2003, 09:09 PM
Thanks for all the answers!