javascript error with php variable passing in codeigniter

815
function something(frm,i){
//var ch=frm.outof1.value;
for(var j=1;j<=i;j++)
{
    //var b="outof" + j;
    alert(frm.outof+j.value);

}
//alert("outof" + i);
return false;
}

 $js='onClick="something(this.form,\''. $ii .'\')"';
  echo form_button('mybutton', 'Click Me', $js);

and getting output NAN where in html this is // echo form_input('outof'.$i,''); // the form input.

866

Answer

Solution:

First, you will want to make sure the passed$ii is made into the correct type (not a string) by usingparseInt. Then you construct the form input name by concatenating'outof' and the number before evaluating.value.

function something(frm, i)
{
    for(var j = 1; j <= parseInt(i); ++j) {
        alert(frm['outof' + j].value);
    }
}
174

Answer

Solution:

alert(parseInt(frm.outof) + parseInt(j.value))

Most likely, you're trying to sum up strings, and not integers

People are also looking for solutions to the problem: php - How to change the <font size> of SC Editor?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.