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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submit When return False???

Status
Not open for further replies.

rac13

Programmer
Dec 3, 2000
20
SG
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!-- Begin
function checkFields() {
count = document.GRN.TotalItem.value;
for (var j = 1; j <= count ; j++)
{
Rec = eval(&quot;document.GRN.QtyRecevied&quot; + j);
Order = eval(&quot;document.GRN.QtyOrdered&quot; + j);
if (Rec.value > Order.value)
{
alert(&quot;There is an error in quantity. Please check.&quot;);
return false;
}
}
return true;
}
function checkSubmit() {
if (checkFields())
{
document.GRN.submit();
}
}
// End -->
</SCRIPT>

<cfform action=&quot;GRN_action.cfm&quot; method=&quot;POST&quot; enablecab=&quot;No&quot; name=&quot;GRN&quot;>


........Codes....


<input type=&quot;image&quot; src=&quot;../../image/save_GRN.gif&quot; onClick=&quot;javascript:checkSubmit()&quot; alt=&quot;Save GRN&quot;>
</cfform>

When it return false, it still go to the action page. Why?
 
because the function is called in an input type ... the proper way to call it is in the form tag
<form .... onsubmit=&quot;return checkSubmit()&quot;>...</form>
don't know about cfform tho, but i did biiiiig sites in coldfusion and never used them - use form instead it's more compliant
 
Then wat abt this?

<input type=&quot;image&quot; src=&quot;../../image/save_GRN.gif&quot; onClick=&quot;javascript:checkSubmit()&quot; alt=&quot;Save GRN&quot;>


I'm using an image as a submit button.
 
if you call your function from the submit button/image/whatever it won't work - to make it work you have to call it from the FORM tag
was the 1st line of my 1st reply !!!!!
 
Yes I know but don't we need a submit button/image to active the submit?
 
yes but the call to the function SHOULD NOT be in this submit button/image if you don't want to submit the form when the return value is false
<form .... onsubmit=&quot;return checkSubmit()&quot;>
...
<input type=&quot;image&quot; src=&quot;../../image/save_GRN.gif&quot; onClick=&quot;submit()&quot; alt=&quot;Save GRN&quot;>
</form>
 
I'm having a similar prpoblem with the following script.

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!-- Begin
function checkSOL_Nbr(field) {
var ok = &quot;yes&quot;;
var temp;
var fieldLength
if (field.value.length == '')
{
ok = &quot;no&quot;;
}

if (ok == &quot;no&quot;) {
alert(&quot;Solicitation Number must be entered prior to submitting to database.&quot;);
field.focus(document.InsrtNSN.S_NBR_AGCY);
field.select(document.InsrtNSN.S_NBR_AGCY);
return false;
}
}
// End -->
</script>

My form tag:
<FORM Name = InsrtNSN ACTION = &quot;Insrt_NSN_Confirmation.asp&quot; Method = Post onSubmit=&quot;checkSOL_Nbr(document.InsrtNSN.S_NBR_RFQ_TYPE);&quot;>

When a user attempts to submit and the field &quot;document.InsrtNSN.S_NBR_RFQ_TYPE&quot; is empty the alert fires, but the form submits anyway once she clicks OK in the Alert window.

I'm trying to have the submission fail and have the field (document.InsrtNSN.S_NBR_AGCY) selected when the OK button in the alert window is clicked.

Thanks for the help.
 
I figured out my problem. I needed to add the word &quot;Return&quot; to the onSubmit event handler.

However, I now would like to have this function check four seperate fields, one of which is a Select list. (I've attached the value '' to the word Select in the list so that &quot;Select&quot; will not be entered in the database if a user overlooks the field.)

When I try to add functions or additional fields to the onSubmit handler I keep getting the error that the object does not support this function.

Thanks,

Roy
 
rac is that working for you now ??
uncle roydee, which object does not support which function ?? you should be more precise so that people here can really help you ! anyway i guess you try to get the select field value this way : document.formname.selectname.value - the proper way is : document.formname.selectname.options[document.formname.selectname.selectedIndex].value
good luck !
 
Sorry about the ambiguity.
I'm trying to have one function validate four fields at once.

The form field that I cannot get to validate is a select list that is populated by a recordset.

Here is the code that creates the select list.

<%
if blnRecordsExist = true then
'check to see if records exist
rstSNBRAGENCY.MoveFirst
'go to first record before looping through
'populate a list box
%>
<select name = &quot;S_NBR_AGCY&quot;>
<%
do while not rstSNBRAGENCY.eof
'loop through records and add item to drop down
%>
<option value = &quot;<%=rstSNBRAGENCY(&quot;S_NBR_AGCY_VAL&quot;)%>&quot; <%
if rstSNBRAGENCY(&quot;S_NBR_AGCY&quot;) = S_NBR_AGCY_update_value then%>selected<%end if%>><%=rstSNBRAGENCY(&quot;S_NBR_AGCY&quot;)%>
</option>
<%
rstSNBRAGENCY.MoveNext
'move to next record
loop
%>
</select>
<%
else
'no records exist so allow user to enter value in text box
%>
no records. enter one.<BR>
<INPUT TYPE=&quot;TEXT&quot; maxlength=6 SIZE=6 NAME=&quot;S_NBR_Agcy&quot;>
<%
end if
%>

Here are the other three fields:

<INPUT TYPE=&quot;TEXT&quot; maxlength=2 SIZE=2 NAME=&quot;S_NBR_YR&quot; value=&quot;<%=S_NBR_YR_update_value%>&quot;>&nbsp;-&nbsp;
<INPUT TYPE=&quot;TEXT&quot; maxlength=1 SIZE=1 NAME=&quot;S_NBR_RFQ_TYPE&quot; onChange=&quot;javascript:this.value=this.value.toUpperCase();&quot;>&nbsp;-&nbsp;
<INPUT TYPE=&quot;TEXT&quot; SIZE=4 NAME=&quot;S_NBR_RFQ_ISSUE_ORDER&quot; maxlength=4 onChange=&quot;javascript:this.value=this.value.toUpperCase();&quot;>

Here is the validate function:

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!-- Begin
function checkSOL_Nbr(field) {
var ok = &quot;yes&quot;;
var temp;
var fieldLength
if (field.value.length == '')
{
ok = &quot;no&quot;;
}

if (ok == &quot;no&quot;) {
alert(&quot;Solicitation Number must be entered prior to submitting to database.&quot;);
field.focus(document.InsrtNSN.S_NBR_AGCY);
field.select(document.InsrtNSN.S_NBR_AGCY);
return false;
}
}
// End -->
</script>


And here is the event handler, which I placed in the Form tag:

onSubmit=&quot;return checkSOL_Nbr(document.InsrtNSN.S_NBR_RFQ_TYPE);&quot;

I've only been able to get the function to check one field at a time, I'm sure it's a syntax error on my part.

Thanks for any help offered.
 
i don't have the time o go thru all your code
anyway it seems you always test ONE field (document.InsrtNSN.S_NBR_RFQ_TYPE) - that's why it won't test ALL fields !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top