0

i have an asp.net mvc4 application , in which i have this form :

  <form method="Post" action="/User/Validate_Expert_Decision" target="_parent">
      <span>
          <b style="color:red" >Votre avis</b>
          <br />
          <br />

          <input type="radio" name="avis" value="1" checked>Validé &nbsp &nbsp &nbsp &nbsp
          <input type="radio" name="avis" value="2">Refusé &nbsp &nbsp &nbsp &nbsp
          <input type="radio" name="avis" value="3">Demande de spécification &nbsp &nbsp &nbsp &nbsp
          <input type="radio" name="avis" value="4">Demande d'analyse 
          <br />
          <br />
          <br />

      </span>
    <span>
        <b style="color:red" >
        Votre justification * 
        <b />

          <br />
          <br />
      <textarea rows="16" cols="75" name="justification"></textarea>
    </span>

    <input type="hidden" name="elem" value="0"  id="elem"/>
    <p> 
      <input type="submit" name="submit">
      <input type="button" name="cancel" value="Annuler" onClick="closebox()">
    </p>
  </form>

i need to add the attribute required to the textarea justification when the radio button takes 2, 3 or 4 as a value ie only for the first value the justification input isn't required.

So, how can i do this task?

2 Answers 2

1
<script>
    $(document).ready(function () {
        $('input[name="avis"]').change(function () {
            var t = $('textarea[name="justification"]');

            if ($(this).val() != 1)
                t.attr('required', 'required');
            else
                t.removeAttr('required');
        })
    })
</script>
Sign up to request clarification or add additional context in comments.

Comments

1

Anything like this?

$("input[name='avis']").on("change", function () {
    var value = $(this).val();
    $('td[name=justification]').prop("required", value != "1");
});

Comments

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.