469,954 Members | 1,759 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,954 developers. It's quick & easy.

define the submit button

Hello, I'd like to pass the "levelbtn" value when I click the filter
button, but there are also other submit form buttons.

I defined as "document.testform.submit();" in the javascript, but I
don't think it is right.

-----------------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>
<script language="JavaScript">
<!--
function submitForm(){
if (document.testform.leveltype.value != "" &&
document.testform.officename.value != "") {
document.testform.submit();
}
else {
alert("Please select level and/or office before pressing the
button");
}
}
//-->
</script>

<form name="testform" method="post" action="test02.cfm">

<input type="text" name="leveltype" value="" />

<input type="text" name="officename" value="" />

<input type="Button" name="levelbtn" value="Filter"
onclick="submitForm()" />

<input type="submit" name="innerbtn" value="inner" />

<input type="submit" name="outerbtn" value="outer" />

</form>
</body>
</html>
Jul 23 '05 #1
1 1845
reneecccwest wrote:
Hello, I'd like to pass the "levelbtn" value when I click the filter
button, but there are also other submit form buttons.

I defined as "document.testform.submit();" in the javascript, but I
don't think it is right.
Correct. Submit will be impossible without JavaScript then, aside from
the fact that you never know what is considered the default submit button.
[...]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
There is the URL of the DTD (the system identifier) missing before
it is Valid HTML. The W3C Markup Validator is misguiding here as
it uses an Open Catalog for mapping DOCTYPE declarations to files.
(See comp.infosystem.www.authoring.misc)
<html>
<head>
<title>Untitled</title>
I hope this is different in the real document.
</head>

<body>
<script language="JavaScript">
This should read

<script type="text/javascript">
<!--
function submitForm(){
function submitForm(o)
{
var result = false;
if (document.testform.leveltype.value != "" &&
document.testform.officename.value != "") {
document.testform.submit();
}
else {
alert("Please select level and/or office before pressing the
button");
}
var e = o && o.elements;
if (e)
{
if (e['leveltype'].value != ""
&& e['officename'].value != "")
{
result = true;
}
else
{
alert(
"Please select level and/or office before pressing the button");
}
}

return result;
} //-->
</script>
You better place the script in the "head" element.
<form name="testform" method="post" action="test02.cfm">
<form
action="test02.cfm"
method="post"
onsubmit="return submitForm(this)">
<input type="text" name="leveltype" value="" />

<input type="text" name="officename" value="" />

<input type="Button" name="levelbtn" value="Filter"
onclick="submitForm()" />

<input type="submit" name="innerbtn" value="inner" />

<input type="submit" name="outerbtn" value="outer" />
This is not XHTML, and there are default values for
some attributes, so you can safely omit them.

<input name="leveltype">
<input name="officename">
<input type="submit" name="levelbtn" value="Filter">
<input type="submit" name="innerbtn" value="inner">
<input type="submit" name="outerbtn" value="outer">
</form>
[...]

HTH

PointedEars
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by rjames.clarke | last post: by
4 posts views Thread by Dmitry Korolyov [MVP] | last post: by
3 posts views Thread by Jeff | last post: by
4 posts views Thread by j1dopeman | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.