Combination of CGI and JavaScript

I use C to write CGI, I think a JavaScript control of a button to select the following
<script language=javascript type=text/javascript>
var flag=1;
function selectAll(){
if(flag==1){
if(form1.chxSong.length!=undefined){");
for (var i=0;i<form1.chxSong.length;i++)
form1.chxSong.checked=true;
}else{
form1.chxSong.checked=true;
}
flag=0;
}else{
if(form1.chxSong.length!=undefined){
for (var i=0;i<form1.chxSong.length;i++)
form1.chxSong.checked=false;
}else{
form1.chxSong.checked=false;
}
flag=1;
}
}
</script>
I tried it:
printf("<html><head>");
printf("<title></title>");
printf("<script language=javascript type=text/javascript>");
printf("var flag=1;");
printf("function selectAll(){");
printf("if(flag==1){");
printf("if(form1.chxSong.length!=undefined){");
printf("for (var i=0;i<form1.chxSong.length;i++)");
printf("form1.chxSong.checked=true;");
printf("}else{");
printf("form1.chxSong.checked=true;");
printf("}");
printf("flag=0;");
printf("}else{");
printf("if(form1.chxSong.length!=undefined){");
printf("for (var i=0;i<form1.chxSong.length;i++)");
printf("form1.chxSong.checked=false;");
printf("}else{");
printf("form1.chxSong.checked=false;");
printf("}");
printf("flag=1;");
printf("}");
printf("}");
printf("</script>");

I don't know why the JavaScript does not work, please JavaScript in CGI writing that I put them all in the printf inside it?

Started by Dolores at November 17, 2016 - 5:11 AM

Alas, alas!!

Posted by Dolores at November 24, 2016 - 5:56 AM

The direct use of printf tired. Try eybuild.


The cause of the error:
1 does not define a form1 and chxSong

2. >> if(form1.chxSong.length!=undefined){");
Excess {"
3. >> form1.chxSong.checked=true;
A form1.chxSong. array.[i].checkeed = true;

Refer to this section of code:

<html><head>
<title></title>
<script language=javascript type=text/javascript>
<!--
var flag=1;
function selectAll(form1){
if(flag==1){
if(form1.chxSong.length!=undefined){
for (var i=0;i<form1.chxSong.length;i++)
form1.chxSong[i].checked=true;
}else{
form1.chxSong[i].checked=true;
}
flag=0;
}
else{
if(form1.chxSong.length!=undefined){
for (var i=0;i<form1.chxSong.length;i++)
form1.chxSong[i].checked=false;
}else{
form1.chxSong[i].checked=false;
}
flag=1;
}

return false;
}
-->
</script>
</head>
<body>
<form name="form1" action="xxx">
<input type=checkbox name=chxSong>checkbox1<br>
<input type=checkbox name=chxSong>checkbox2<br>
<input type=checkbox name=chxSong>checkbox3<br>
<input type=checkbox name=chxSong>checkbox4<br>
<input type=checkbox name=chxSong>checkbox5<br>

<input type=submit onclick="return selectAll(form1);">
</body>

Good Luck!

Posted by Cheryl at December 04, 2016 - 6:02 AM

Have questions please GOOGLE,BAIDU

Posted by Samuel at December 14, 2016 - 6:52 AM

JavaScript individually packaged in a file

Implementation of JS transfer function parameters

Not necessary with HTML print

Posted by Marshall at December 26, 2016 - 7:32 AM