0

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.

1
  • show reset() and validate() Commented May 14, 2014 at 5:19

1 Answer 1

2

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">
Sign up to request clarification or add additional context in comments.

4 Comments

how I can pass "www.something.com" from validateAndRelocate function?
Where do you want to pass, Please elaborate.
<input type="SUBMIT" onclick="validateAndRelocate(www.somethg.com) value="Update">
function validateAndRelocate(relocationURL) { if(!validate()) { location.href = relocationURL; } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.