1

How do I not trigger validation of the following form once using

javascript: form.action

I have 2 Submit buttons first one must use sellitem1.php as action and not use JQuery VALIDATION but 2nd one must VALIDATE form and use action listed in the Form Action: upload.php.

2nd Button is working well :)

<form method="post" name="UploadForm" id="UploadForm"
action="upload.php" enctype="multipart/form-data" >

<input  type="text" class="button_date"  name="price" id="price"
value="" size="15" />

<input class="button2" style="border-right:none; font-size:13px;"
name="Back" id="Back" type="submit"  value="Back" onclick="javascript:
form.action='sellitem1.php';"/>

<input class="button2" style="border-right:none; font-size:13px;"
name="List Item" id="submit" type="submit" value="List Item"
onClick="removeFocus()"/> </form>


<script>

$( "#UploadForm" ).validate({
       errorLabelContainer: "#messageBox",   wrapper: "td",
       rules: {  price: {
    required: true,
    number: true,
    range: [1.00, 500000.00]

    }   } }); </script>
freejosh
  • 11,263
  • 4
  • 33
  • 47
user974435
  • 377
  • 2
  • 13
  • 31

1 Answers1

0

Something like the following should work. So basically you'd call the validate() on click event on the button for which you want to run validation.

// Javascript

$('#Back').click(function (evt) {
    $('#UploadForm').attr('action', 'sellitem1.php');
});

$('#submit').click(function (evt) {
    removeFocus();
    return $("#UploadForm").validate({
        errorLabelContainer: "#messageBox",
        wrapper: "td",
        rules: {
            price: {
                required: true,
                number: true,
                range: [1.00, 500000.00]
            }
        }
    });
});

It's better practice not to embed javascript/css code inline. You could update your html as follows (Note that I only removed your onclick attributes and not style):

<form method="post" name="UploadForm" id="UploadForm"
action="upload.php" enctype="multipart/form-data" >

    <input  type="text" class="button_date"  name="price" id="price"
value="" size="15" />

    <input class="button2" style="border-right:none; font-size:13px;"
name="Back" id="Back" type="submit"  value="Back" />

    <input class="button2" style="border-right:none; font-size:13px;"
name="List Item" id="submit" type="submit" value="List Item" /> 
</form>

Update: Here is the fiddle showing how this works http://jsfiddle.net/M3LRd/

vee
  • 38,255
  • 7
  • 74
  • 78
  • it doesnt work, no validation and always redirect to curentitems.php :( – user974435 Jul 28 '13 at 07:18
  • that si the solution Add a class of cancel to the button that shouldn't validate. stackoverflow.com/questions/203844 – user974435 Jul 28 '13 at 07:26
  • @user2511459, I've added fiddle as a demo with the code in this answer. But yes, `class="cancel"` will also work. – vee Jul 28 '13 at 13:30