Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

<a href="salesforcemaintain.asp" onClick="document.form1.submi

Status
Not open for further replies.

jcroft

Programmer
Aug 23, 2001
52
US
Is this good code to get a submit on a form to work...if so
how do I refer to it in an "IF" statement when it is clicked?....any better way to do this without using the input button method would be appreciated.

<a href=&quot;salesforcemaintain.asp&quot; onClick=&quot;document.form1.submit()&quot;>
<img src=&quot;images/bwbullet.gif&quot; border=0><FONT FACE='Verdana, Arial' SIZE=2>
Add to Database</FONT></a>
 
Looks fine. You could also abstract your .submit() into a separate javascript function if you needed to do anything else before you submit.

onClick=&quot;submitMe();&quot;

function submitMe(){
//some other stuff
if (someCondition)
document.form1.submit();
}

Is that ^^ what you mean by referring to it in an if statement? I don't think I quite got your meaning there.

:)
paul

penny.gif
penny.gif
 
Paul,

Thank you, yes, I do believe you answered what I need, I will try the javascript...

June
 
I assume you need to run some sort of validation, like check a checkbox etc, try :

<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
function mycheck() {
if (document.myform.chkbx.checked) {
document.myform.submit()
} else {
alert('You must check the entry')
document.myform.chkbx.focus()
}
}
//-->
</script>


<form name=&quot;myform&quot; action=&quot;salesforcemaintain.asp&quot; method=&quot;post&quot;>
<input type=&quot;checkbox&quot; name=&quot;chkbx&quot;>
<a href=&quot;JavaScript:mycheck()&quot;><img src=&quot;images/bwbullet.gif&quot; border=0><FONT FACE='Verdana, Arial' SIZE=2>Add to Database</FONT></a>
</form>
Regards

Big Dave

davidbyng@hotmail.com


** If I am wrong I am sorry, but i'm only trying to help!! **

 
Big Dave,

All help is appreciated...the more I can learn about javascript the better off I am...thank you.

June
 
Big Dave,

Problem with where to place what....

My page resembles:


<%
IF Request.Form(&quot;chkbx&quot;) = checked then
'add to database
ELSE
'display form...this is where I put your code...should it be elsewhere?

<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
  function mycheck() {
if (document.form1.chkbx.checked)
document.form1.submit()
} else {
alert('You must check the entry')
document.form1.chkbx.focus()
}
}
//-->
</script>
<HTML>...etc then I put in this code...

<form method=post action=&quot;salesforcemaintain.asp&quot; id=form1 name=form1>

...then in table I put this...

<a href=&quot;JavaScript:mycheck()&quot;><input type=&quot;hidden&quot; name=&quot;chkbx&quot;>
<img src=&quot;images/bwbullet.gif&quot; border=0><FONT FACE='Verdana, Arial' SIZE=2>
Add to Database</FONT></a>

When I initially load page the form does not display...it just adds blank row to database...do I need to set chkbx to false, or do I just have code in wrong place?

June
 
The problem is, you can't use if check box = checked in asp.

Instead you need to give the checkboxa a value :

Code:
<%
If Request.Form(&quot;chkbk&quot;) = &quot;imchkd&quot; Then
'database stuff
Else
'show form again
End If
%>

The check box should look like this :

Code:
<input type=&quot;checkbox&quot; name=&quot;chkbx&quot; value=&quot;imchkd&quot;>
Regards

Big Dave

davidbyng@hotmail.com


** If I am wrong I am sorry, but i'm only trying to help!! **

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top