Pass 2 parameters to javascript function from <INPUT onclick
Posted: Tue Jul 15, 2008 10:31 am
Hi
Judging by the number of posts I've seen on this, there's a fair bit of confusion as how to code the syntax for passing two parameters from php to a javascript? This includes me
.
I have a short function to make sure only one checkbox ever gets clicked. It appears in "view source" as follows:-
<script language="JavaScript"><!--
maxBoxes = 1;
boxesChecked = 0;
function checkIt(theBox, my_msg) {
if (boxesChecked+1 > maxBoxes) {
alert('error msg='+my_msg);
return false;
}
boxesChecked++
return true;
}
//-->
</script>
I call it from an input field which gets rendered as below, from "view source":-
<input type='checkbox' onClick='if (this.checked) return checkIt(this,'Only one Selection box can be ticked'); else boxesChecked--' name="del_me[]" value="54">
It's coded in php as:-
$msgline = $my_page['msg20'];
echo "<input type='checkbox' onClick='if (this.checked) return checkIt(this,'".$msgline."'); else boxesChecked--' name=\"del_me[]\" value=\"$row[holiday_id]\">";
When I call this with one parameter i.e. return checkIt(this), the function runs fine but when I add in the extra parameter with the string I want in the pop-up window, the function doesn't appear to run at all?
I've run out of syntax steam now and wondered if someone could help me?
Thanks
Judging by the number of posts I've seen on this, there's a fair bit of confusion as how to code the syntax for passing two parameters from php to a javascript? This includes me
I have a short function to make sure only one checkbox ever gets clicked. It appears in "view source" as follows:-
<script language="JavaScript"><!--
maxBoxes = 1;
boxesChecked = 0;
function checkIt(theBox, my_msg) {
if (boxesChecked+1 > maxBoxes) {
alert('error msg='+my_msg);
return false;
}
boxesChecked++
return true;
}
//-->
</script>
I call it from an input field which gets rendered as below, from "view source":-
<input type='checkbox' onClick='if (this.checked) return checkIt(this,'Only one Selection box can be ticked'); else boxesChecked--' name="del_me[]" value="54">
It's coded in php as:-
$msgline = $my_page['msg20'];
echo "<input type='checkbox' onClick='if (this.checked) return checkIt(this,'".$msgline."'); else boxesChecked--' name=\"del_me[]\" value=\"$row[holiday_id]\">";
When I call this with one parameter i.e. return checkIt(this), the function runs fine but when I add in the extra parameter with the string I want in the pop-up window, the function doesn't appear to run at all?
I've run out of syntax steam now and wondered if someone could help me?
Thanks