Click to See Complete Forum and Search --> : What's wrong with my code?


gcook1
11-09-2005, 08:25 AM
I have a ASP form that's giving me fits! I have a question on the form ("Have all lines on this sales order shipped complete?") with YES/NO radio buttons. If the user chooses NO, when the submit button is clicked I want a pop up window saying "Form may not be submitted until order is completely shipped". I can't get it to work. Here's my code:

The question coding:
<tr><td colspan=2><%= QUESTION10 %></td>
<td><input type="radio" name="Answer10" value="Yes">Yes&nbsp;&nbsp;
<input type="radio" name="Answer10" value="No">No </td></tr>

<%= QUESTION10%> gets the wording for the question from a CONST set above the html.

The message box coding:
<script language="VBScript">
dim validation
function MyForm_OnSubmit
validation = True
If(document.MyForm.Answer10.Value) = "No" Then
MsgBox("Form may not be submitted until order is completely shipped")
validation = False
End If

If validation = True Then
MyForm_OnSubmit = True
Else
MyForm_OnSubmit = False
End if
end Function

</script>

Any ideas why it doesn't work? Or is there a better way to do this?

Thanks for your help!

lmf232s
11-09-2005, 11:38 AM
are you getting any errors?

When does the function get called. From the submit button or does it get called from with in ASP server side code?

gcook1
11-09-2005, 12:58 PM
It's supposed to get called when the submit button is clicked. In the same function call (MyForm_OnSubmit), I also do a validation check on the email address used in the To: field. If the To email address doesn't have an "@" sign in it, a message box pops up warning the user. That was working fine until I added the code for validating the "Yes/No". Now it's like the function doesn't work at all.

I keep thinking it has something to do with the If (document.MyForm.Answer10.Value)="No" part. But why wouldn't that be a valid statement?

lmf232s
11-09-2005, 01:42 PM
Here is my example

<script language="VBScript">
dim validation
function MyForm_OnSubmit
validation = True

If(document.Test.Answer10(1).Checked) Then
MsgBox("Form may not be submitted until order is completely shipped")
validation = False
End If

If validation = True Then
MyForm_OnSubmit = True
Else
MyForm_OnSubmit = False
End if
end Function
</script>

<form name=Test method=post>
<input type="radio" name="Answer10" value="Yes">Yes
<input type="radio" name="Answer10" value="No">No
<input type=button name=submit value=submit onclick="MyForm_OnSubmit()">
</form>


Here is your example modified
This is really the only line that needs to be modified

If(document.MyForm.Answer10(1).checked) Then


I guess you could do this

if(document.MyForm.Answer10(1).value) = "No" then


But you really just need to see if its selected and not = "No", if its selected then the user had to select No. You could do it either way i guess.

See if that helps.

stacekz
11-09-2005, 02:10 PM
Try this



<script language="JavaScript" type="text/JavaScript">

function checkform() {

shipping_ok=true;
if (document.MyForm.Answer10(1).value == "") shipping_ok = false;

form_ok = (shipping_ok);

if (shipping_ok == false) {

alert("Form may not be submitted until order is completely shipped");

}

return form_ok;

}

//-->
</script>




Then where your form starts put this in it

<form name="form name" method="post" onsubmit="return checkform()">