Link to home
Start Free TrialLog in
Avatar of dejandejanovic
dejandejanovic

asked on

When adding onclick=location.href under button control the validation not working! Need someone to check the code.

Hello,
I'm newbie with MVC, still learning, I currently trying to compose contact form. And have problem with the validation procedure of below html code.
On the bottom of the code are two buttons:
- First one does not have OnClick event, and the validation works fine!
- second have an OnClick event, which should later call the controll code, but the validation stopped working?!

Need heeeelp! SOS! :-)


@using (Html.BeginForm())
{ 
    <div class="controls">
        <div class="row">
            <div class="col-lg-4">
                <div class="form-group">
                    <label for="form_name">Firstname *</label>
                    <input id="form_name" type="text" name="name" class="form-control" placeholder="Please enter your firstname *" required="required" data-error="Firstname is required.">
                    <div class="help-block with-errors"></div>
                </div>
            </div>
            <div class="col-lg-4">
                <div class="form-group">
                    <label for="form_lastname">Lastname *</label>
                    <input id="form_lastname" type="text" name="surname" class="form-control" placeholder="Please enter your lastname *" required="required" data-error="Lastname is required.">
                    <div class="help-block with-errors"></div>
                </div>
            </div>
        </div>
        </div>
        <div class="row">
            <div class="col-lg-4">
                <div class="form-group">
                    <label for="form_email">Email *</label>
                    <input id="form_email" type="email" name="email" class="form-control" placeholder="Please enter your email *" required="required" data-error="Valid email is required.">
                    <div class="help-block with-errors"></div>
                </div>
            </div>
            <div class="col-lg-4">
                <div class="form-group">
                    <label for="form_phone">Phone *</label>
                    <input id="form_phone" type="tel" name="phone" class="form-control" required="required" placeholder="Please enter your phone">
                    <div class="help-block with-errors"></div>
                </div>
            </div>
                   </div>
                <div class="row">
                    <div class="col-lg-4">
                        <div class="form-group">
                            <label for="form_phone">Company</label>
                            <input id="form_phone" type="text" name="company" class="form-control" placeholder="Please enter your company name">
                            <div class="help-block with-errors"></div>
                        </div>
                    </div>
                </div>
               
                <p>
            
        </p>    
        <div class="row">
            <button style="width:200px" type="submit" class="btn btn-primary btn-lg">1 Send</button>
            <button onclick="location.href='@Url.Action("contact", "Home")'" style="width:200px" type="submit" class="btn btn-primary btn-lg">2 Send</button>

    </div>
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial