Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong with my code??

Status
Not open for further replies.

colep

Programmer
Jul 18, 2002
58
0
0
US
I am getting an expected identifier error with this code. And I don't know why I'm getting it... Any help would be appreciated!

Code:
<SCRIPT LANGUAGE='JavaScript'>
<!--
  function delete_alternative(form,i) {
    if (form.delete[i].checked == true) form.delete_alt[i].value = &quot;DELETE&quot;;
    else form.delete_alt[i].value = &quot;KEEP&quot;;
    return;
  }
//-->
</SCRIPT>

<?php
  echo &quot;<B><FONT SIZE=2 COLOR=#C90707>Remove this Alternative $i? :
    <INPUT TYPE=HIDDEN NAME=delete_alt[$i] VALUE=''>
    <INPUT TYPE=CHECKBOX NAME=delete[$i] VALUE='DELETE' onClick=\&quot;delete_alternative(this.form,$i);\&quot;>
  </FONT></B>&quot;;
?>

Thanks in advance,
Cole ;)
 
show us the source code after it's been processed by php and sent to the browser rather than the actual php code...

=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
Ok, here you go....

Code:
<SCRIPT LANGUAGE='JavaScript'>
<!--
  function delete_alternative(form,i) {
    if (form.delete[i].checked == true) form.delete_alt[i].value = &quot;DELETE&quot;;
    else form.delete_alt[i].value = &quot;KEEP&quot;;
    return;
  }
//-->
</SCRIPT>

<FONT SIZE=3><B><CENTER>Alternative # 1</CENTER></B></FONT>
<B><FONT SIZE=2 COLOR=#C90707>Remove this Alternative 0? :
  <INPUT TYPE=HIDDEN NAME=delete_alt[0] VALUE=''>
  <INPUT TYPE=CHECKBOX NAME=delete[0] VALUE='DELETE' onClick=&quot;delete_alternative(this.form,0);&quot;>
</FONT></B>

Cole ;)
 
Since you are using the array of form objects to refer to these, remove the brackets [0] here...

<INPUT TYPE=HIDDEN NAME=delete_alt[0] VALUE=''>
<INPUT TYPE=CHECKBOX NAME=delete[0] VALUE='DELETE' onClick=&quot;delete_alternative(this.form,0);&quot;>


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
But the problem is the delete and delete_alt form elements are arrays... The form is repeated for each item in the package. And I need to access just the one that gets checked to delete that item. Is there another way to do this???

Cole ;)
 
<SCRIPT LANGUAGE='JavaScript'>
<!--
function delete_alternative(form,i)
{
if (form.delete.checked == true)
{
form.delete_alt.value = &quot;DELETE&quot;;
}
else
{
form.delete_alt.value = &quot;KEEP&quot;;
return;
}
}
//-->
</script>
 
<INPUT TYPE=HIDDEN NAME=delete_alt0 VALUE=''>
<INPUT TYPE=CHECKBOX NAME=delete0 VALUE='DELETE' onClick=&quot;delete_alternative(this.form.name,0);&quot;>


<script>
function delete_alternative(formName, ext){
isChecked = eval(&quot;document.&quot; + formName + &quot;.delete&quot; + ext + &quot;.checked&quot;)
if (isChecked){
eval(&quot;document.&quot; + formName + &quot;.delete_alt&quot; + ext + &quot;='DELETE'&quot;)
}
else{
eval(&quot;document.&quot; + formName + &quot;.delete_alt&quot; + ext + &quot;='KEEP'&quot;)
}
}
</script>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
The delete_alt hidden form element needs to be an array in order for me to catch when the form is submited and just adding a number to the end of the name (delete_alt0) isn't going to cut it. It needs to be an array, because the number of items in the package is unknown.

The form looks like this...

Item #1:
Code:
<FONT SIZE=3><B><CENTER>Alternative # 1</CENTER></B></FONT>
<B><FONT SIZE=2 COLOR=#C90707>Remove this Alternative? :
  <INPUT TYPE=HIDDEN NAME=delete_alt[0] VALUE=''>
  <INPUT TYPE=CHECKBOX NAME=delete[0] VALUE='DELETE' onClick=&quot;delete_alternative(this.form,0);&quot;>
</FONT></B>

Item #2:
Code:
<FONT SIZE=3><B><CENTER>Alternative # 2</CENTER></B></FONT>
<B><FONT SIZE=2 COLOR=#C90707>Remove this Alternative? :
  <INPUT TYPE=HIDDEN NAME=delete_alt[1] VALUE=''>
  <INPUT TYPE=CHECKBOX NAME=delete[1] VALUE='DELETE' onClick=&quot;delete_alternative(this.form,1);&quot;>
</FONT></B>

and so on...
 
it is unnecessary and usually creates problems to use square brackets in form element names - the fact that an element shares its name with another makes it an array, and you do not need to give it an index [1]

should be like this:

<FONT SIZE=3><B><CENTER>Alternative # 1</CENTER></B></FONT>
<B><FONT SIZE=2 COLOR=#C90707>Remove this Alternative? :
<INPUT TYPE=HIDDEN NAME=delete_alt VALUE=''>
<INPUT TYPE=CHECKBOX NAME=delete VALUE='DELETE' onClick=&quot;delete_alternative(this.form,0);&quot;>
</FONT></B>


Item #2:

<FONT SIZE=3><B><CENTER>Alternative # 2</CENTER></B></FONT>
<B><FONT SIZE=2 COLOR=#C90707>Remove this Alternative? :
<INPUT TYPE=HIDDEN NAME=delete_alt VALUE=''>
<INPUT TYPE=CHECKBOX NAME=delete VALUE='DELETE' onClick=&quot;delete_alternative(this.form,1);&quot;>
</FONT></B>


=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
If you have to have an array then it should be like this...

Item #1:
<INPUT TYPE=HIDDEN NAME=delete_alt VALUE=''>
<INPUT TYPE=CHECKBOX NAME=delete VALUE='DELETE' onClick=&quot;delete_alternative(this.form,0);&quot;>

Item #2:
<INPUT TYPE=HIDDEN NAME=delete_alt VALUE=''>
<INPUT TYPE=CHECKBOX NAME=delete VALUE='DELETE' onClick=&quot;delete_alternative(this.form,1);&quot;>

Then your form handler makes an array out of the form elements which are passes as comma separated values...

Now you can refer to them as arrays in javascript.
if (form.delete.checked == true) form.delete_alt.value = &quot;DELETE&quot;;
else form.delete_alt.value = &quot;KEEP&quot;;




Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
Thanks for your help guys but I found an easier way to accomplish the task at hand using php....

Thanks again for your help,
Cole ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top