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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form.elements

Status
Not open for further replies.

novice2004

Programmer
Feb 2, 2004
62
US
Help please.
Does anybody know if it is possible to send a string from php to JavaScript and then to concatenate it into object
because it does not work for me.
Gives me "Error on Page".
Thank you.



<FORM NAME="form" ID="form" ACTION="Layout.php" METHOD="post"

<input type="checkbox" name="title[]" value="1" />
<input type="checkbox" name="title[]" value="2" />
<input type="checkbox" name="title[]" value="3" />

$v1 = "form";

$v2 = "elements[\"title[]\"]";



print("<a href=\"javascript:document.form.submit()\" onClick=\"return validate(" . $v1 . "," . $v2 . ")\" >GO</a>");




function validate(v1,v2)
{


field = eval(v1 + "." + v2);

return ( validateCheckbox(field) );
}




function validateCheckbox(field)
{
for (i = 0; i < field.length; i++)
{ if(field.checked == true) return true; }

alert("Please select at least one checkbox.");
return false;
}
 
1) Never use "form" as a form name. Instead, use something like "form1".

2) You're most likely getting into a double-quote induced hell. Try something like this:

Code:
print '<a href="document.form.submit();" onclick="return validate(\'' . $v1 . '\',\'' . $v2 . '\');">GO</a>';

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Side note: rather than eval() stuff use something like this:
Code:
$v2 = "title[]";
...
function validate(v1,v2)
{   field = document.forms[v1].elements[v2];
    return ( validateCheckbox(field) );
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top