trickyidiot
asked on
JS+Form - onClick populate text field with checkbox values - not working
Trying to get checkbox values to populate a text field (soon to be a hidden text field on an onClick event
I'm getting an error saying the function is not defined... help?
<script type="text/javascript">
function stringTogether(form) {
// Checking if at least one period button is selected. Or not.
var total=""
for(var i=0; i < document.form1.statusList. length; i++){
if(document.form1.scripts[ i].checked )
total +=document.form1.scripts[i ].value + ","
}
document.form1.strung.valu e = total;
}
</script>
<form name="form1">
<strong>Select which user status levels you would like to exclude:</strong>
<br /><br />
<%
'' get all status codes available
SET rsStatus = server.createObject("ADODB .Recordset ")
sql = "sql query removed for experts exchange - not necessary"
rsStatus.Open sql,dbConn,1
While NOT rsStatus.eof
%>
<input type="checkbox" name="statusList" value="<%=rsStatus("id")%> "> <%=rsStatus("title")%><br />
<%
rsStatus.movenext
wend
%>
<br />
<input type="text" name="strung" value="">
<input type="button" onClick="javascript:string Together(t his);" name="submit" value="submit">
</form>
I'm getting an error saying the function is not defined... help?
<script type="text/javascript">
function stringTogether(form) {
// Checking if at least one period button is selected. Or not.
var total=""
for(var i=0; i < document.form1.statusList.
if(document.form1.scripts[
total +=document.form1.scripts[i
}
document.form1.strung.valu
}
</script>
<form name="form1">
<strong>Select which user status levels you would like to exclude:</strong>
<br /><br />
<%
'' get all status codes available
SET rsStatus = server.createObject("ADODB
sql = "sql query removed for experts exchange - not necessary"
rsStatus.Open sql,dbConn,1
While NOT rsStatus.eof
%>
<input type="checkbox" name="statusList" value="<%=rsStatus("id")%>
<%
rsStatus.movenext
wend
%>
<br />
<input type="text" name="strung" value="">
<input type="button" onClick="javascript:string
</form>
ASKER
Good catch, however I am still receiving the same error
What error and when do you get it? What browser are you using? Change
<input type="button" onClick="javascript:string Together(t his);" name="submit" value="submit">
to
<input type="button" onClick="stringTogether(th is);" name="submit" value="submit">
as javascript: is not needed. To further debug change
function stringTogether(form) {
to
function stringTogether(form) {
alert("Hello");
do you get this alert?
<input type="button" onClick="javascript:string
to
<input type="button" onClick="stringTogether(th
as javascript: is not needed. To further debug change
function stringTogether(form) {
to
function stringTogether(form) {
alert("Hello");
do you get this alert?
Also, you will have a problem if your result set only returns one result. The statement document.form1.statusList. length will be undefined, because you will only have one checkbox rendered by your ASP code.
ASKER
ok, so if my function is bunk, do you know of a better way to achieve what I'm trying to do?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is there more content to this page? I feel like there might be an error in your ASP code that is causing portions of the page not to render.
if(document.form1.scripts[
total +=document.form1.scripts[i
to
if(document.form1.statusLi
total +=document.form1.statusLis