0

how can i create a condition for multiple checkbox!

Input Field ID =" INsrvOtr "

CheckBox ID = "INsrv"

let's say that the that the user has two options,either put a value on the input field or choose any value from the checkbox but he can only choose "ONE" of the two options

Checkbox:

 <input id="INsrv" name="INopt" type="checkbox" value="1" />1<br>

Input field:

<input id="OUTsrvOtr" name="OUToptOtr" type="text" value="" onblur="valINP()"/><br><br>

if the user inputs a value in the input field this will happen

if "input field" is not empty, class of all the "checkbox" will not contain a value.

<script>
function valINP(){
    $("#INsrv1").prop('class','text')
    $("#INsrvOtr").prop('class','validate[required] text-input text')
    }
}
</script>

or if the user chooses to check the checkbox this will happen

and if the "checkbox" is not selected,class of "input field" will not contain a value.

<script>
$(document).ready(function() {
    $("input[name$='INopt']").click(function() {
    $("#INsrv1").prop('class','validate[minCheckbox[1]] checkbox text')
    $("#INsrvOtr").prop('class','text')
    });
});
</script>

or if both is not selected

the script will contain this two:

 $("#INsrv").prop('class','validate[minCheckbox[1]] checkbox text')
 $("#INsrvOtr").prop('class','validate[required] text-input text')
telexper
  • 2,381
  • 8
  • 37
  • 66
  • You didn't say what libraries you're using, what exactly do you want to achieve, and what exactly is the problem that you're getting. I don't expect many answers to your question unless you add more details and real code examples with HTML that you're working on, preferably using [jsFiddle](http://jsfiddle.net/) or [JS Bin](http://jsbin.com/). – rsp Sep 30 '12 at 19:43

2 Answers2

0

try optimize your code, some useful optimization for selecting controls http://api.jquery.com/category/selectors/ or http://api.jquery.com/attribute-contains-prefix-selector/

using some thing like

$("#id|="INsrv"]').prop('class','')

sorry if the syntax goes wrong.

Saboor Awan
  • 1,567
  • 4
  • 24
  • 37
0
// Use this for INsrv([0-9]+)
$('[id^="INsrv"][id!="INsrvOtr"]').each(function() {

});

// Or if you only want to call `prop`
$('[id^="INsrv"][id!="INsrvOtr"]').prop('yourprop', '');

Then you can just call $('#INsrvOtr') separately.

Sly
  • 1,145
  • 7
  • 19
  • INsrv([0-9]+) not working is this correct ? $("#INsrv([0-9]+)").prop('class','') – telexper Sep 30 '12 at 20:00
  • No. Use the code below it. That was a comment, and I was using a regular expression to show what it would be matching. – Sly Sep 30 '12 at 22:46