CJ_world
CJ_world

Reputation: 45

javascript validation check on click condition from HTML

I am new to JS. Please help me resolving the issue.

<tr>
<td align="CENTER">
<input type="SUBMIT" onclick="validate();location=www.somethg.com" value="Update">
</td>
<td align="LEFT">
<input type="BUTTON" value="Reset&nbsp;" onclick="reset()">
</td>
</tr>

Above code is a small piece taken which shall validate on click and will switch to location "somethg".

But i want if validate returns false then only after pressing update it should go to that location else not. How to add this condition. No jquery please.

Upvotes: 0

Views: 145

Answers (1)

Sandeeproop
Sandeeproop

Reputation: 1776

You can write another function for eg.

function validateAndRelocate() {
  if(!validate()) {
   location.href = "www.something.com"
  }
}

And replace

<input type="SUBMIT" onclick="validateAndRelocate()" value="Update">

Upvotes: 2

Related Questions