How to pass variable with space as parameter in onclick function in php

I want to pass a variable with space as a parameter in the onclick function. This is my table value with a space: "sample filename"

   echo '<input type=checkbox name=".$next."  id=".$next." onclick=my1(this.form,this.checked,".$cid.",'".$vfet['file_name']."','".$id."');>';

      

script code

echo ('<script>
                function my1(a,ischeck,cid,file,eid)
                {
                alert("welcome");
                 alert("select"+ischeck);
                 alert("file"+file);
                 }
         </script>');

      

The value of the file is passed nicely if the value has no place.

+3


source to share


2 answers


Make the html legal and put double quotes around the onclick value - at the point where the space makes the browser think it's a separate attribute.

You will also mix your single and double quotes a bit:



echo '<input type="checkbox" name="'.$next.'"  id="'.$next.'" onclick="my1(this.form,this.checked,'.$cid.',\''.$vfet['file_name'].'\',\''.$id.'\');">';

      

+1


source


just try



"'.$cid.'"

, not ".$cid."

or with '\'

0


source







All Articles