• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1674
  • Last Modified:

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.value = 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:stringTogether(this);" name="submit" value="submit">
</form>
0
trickyidiot
Asked:
trickyidiot
  • 3
  • 2
  • 2
1 Solution
 
amit_gCommented:
What is scripts? Change

            if(document.form1.scripts[i].checked)
                  total +=document.form1.scripts[i].value + ","

to

            if(document.form1.statusList[i].checked)
                  total +=document.form1.statusList[i].value + ","
0
 
trickyidiotAuthor Commented:
Good catch, however I am still receiving the same error
0
 
amit_gCommented:
What error and when do you get it? What browser are you using? Change

<input type="button" onClick="javascript:stringTogether(this);" name="submit" value="submit">

to

<input type="button" onClick="stringTogether(this);" 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?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
SirCroftyCommented:
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.
0
 
trickyidiotAuthor Commented:
ok, so if my function is bunk, do you know of a better way to achieve what I'm trying to do?
0
 
amit_gCommented:
Your function is seems to be fine except that it doesn't take care of single checkbox case. That is pretty easy to take care of but before that you should resolve the other problems you are having.
0
 
SirCroftyCommented:
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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now