No matter how you detect an attachment in the server code it would be nice to have an alert before it's submitted rather than getting an error message from the server and going back.
Have you tried editing in more alerts in the JavaScript to see if it's detecting the submit event , whether the function is called and how many "li" elements are in the list? When the page loads there's only one "li" in the list. I don't know what it does, all it contains is . After you load an attachment it should have 2 "li"s.
Try this:
Code:
<script type="text/javascript">
function Check_For_Attachment() {
this.form = document.forms.vbform;
this.attachlist = fetch_object("attachlist_list2");
this.checkInput = document.createElement("input");
this.checkInput.setAttribute("type", "hidden");
this.checkInput.setAttribute("name", "checkattachment");
this.checkInput.setAttribute("value", "");
this.form.appendChild(this.checkInput);
this.alertText = "{vb:rawphrase ca_alert_text}";
YAHOO.util.Event.on(this.form, "submit", function(e){
alert("submit detected");
checkAttachment.checkForm(e)
})
}
Check_For_Attachment.prototype.checkForm = function(e) {
var items = fetch_tags(this.attachlist, "li");
alert("list items " + items.length)
if(items.length < 2) {
alert(this.alertText)
YAHOO.util.Event.stopEvent(e);
} else {
this.checkInput.value = "true";
}
}
YAHOO.util.Event.onDOMReady(function(e) {
checkAttachment = new Check_For_Attachment();
});
</script>