I am using the below code to select random answers in a form
$('table').filter(function() { return ($(this).find('input').size() > 0); }).find('tr').each(function()
{
$(this).find('input').filter(function(){ return (Math.round(Math.random()) == 1); }).each(function()
{
switch(this.type) {
case 'checkbox':
case 'radio':
this.checked = true;
this.trigger('click');
break;
case 'password':
case 'select-multiple':
case 'select-one':
case 'text':
case 'textarea':
$(this).val('12345');
break;
}
});
});
But it is sometimes not answering any input element in a row. Please help me on this.
There’s something wrong with your code. The “type” attribute on the “input” tag can’t be either “select-one”, “select-multiple” or “textarea”.
For textarea, it’s a completely different tag:
<textarea>some text</textarea>For select it’s also a different tag:
<select>for single selects and<select multiple="multiple">for multiple selects.You didn’t specify “when” it doesn’t work, but I believe that’s the case.