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

How to read hidden text box values 1

Status
Not open for further replies.

ksbigfoot

Programmer
Joined
Apr 15, 2002
Messages
856
Location
CA
How do I read in my Javascript function the field (TabValues), loop through the values and check off the checkboxes in my form?
Here is what I have so far, but I am reading incorrectly in the Javascript function.
Javascript function
Code:
function CheckTabsAssigned()
  {
    var strFieldString;
    strFieldString = document.frmTabAssignDoc.TabValues;

    alert(strFieldString);

ASP Code
Code:
<input type="checkbox" name="CheckAll" value="CheckAllTabs" onClick="CheckTabsAssigned()"><b>ALL</b><br>
Do While Not rs.EOF%>
  <input type="hidden" name="TabValues" value="<%=rs.Fields("ID").value%>">
  rs.MoveNext
Loop
 
What your code does is create an array of the form elements named TabValues. To get the values, you should loop through the array.

Code:
function CheckTabsAssigned()
{
var strFieldString;
strFieldString = document.frmTabAssignDoc.TabValues;

for (var si=0;si<strFieldString.length;si++)
  {
  var onevalue = strFieldString[si].value; 
  alert(onevalue);
  //process value however you want
  }
}

Lee
 
Howdy Lee,
When I get to this part, I get an error:
Object expected.
I even commented out everything and put the following line instead of the for statement:
alert(strFieldString.length);
gives the same Object expected error

Here is the code I have in my function:
Code:
 function CheckTabsAssigned()
  {
    var strFieldString;
    
    strFieldString = document.frmTabAssignDoc.TabValues;
	
    for (var si=0;si<strFieldString.length;si++)
    {
//  var onevalue = strFieldString[si].value; 
//  alert(onevalue);
//  //process value however you want
    }
  }
 
You might try this:

Code:
strFieldString = document.forms['frmTabAssignDoc'].elements['TabValues'];

Also makes sure that the form name is correct.

Lee
 
Howdy Lee,
I tried your line of code and I am still getting the same Object expected error.

In my ASP code I have:

<form method="post" name="frmTabAssignDoc" action="Tab.asp">
<input type="checkbox" name="CheckAll" value="CheckAllTabs" onClick="CheckTabsAssigned()"><b>ALL</b><br>
<input type="hidden" name="TabValues" value="65">
<input type="hidden" name="TabValues" value="68">
<input type="hidden" name="TabValues" value="77">
 
I just copied and pasted your code and the Javascript, and it worked like a charm in IE 6.

Here's the entire code I used:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<script language="JavaScript" type="text/javascript">
<!--
function CheckTabsAssigned()
  {
    var strFieldString;
    
    strFieldString = document.forms['frmTabAssignDoc'].elements['TabValues'];
    alert(strFieldString.length);
    
    for (var si=0;si<strFieldString.length;si++)
    {
    var onevalue = strFieldString[si].value; 
    alert(onevalue);
    //process value however you want
    }
  }
//-->
</script>

<body>
<form method="post" name="frmTabAssignDoc" action="Tab.asp">
<input type="checkbox" name="CheckAll" value="CheckAllTabs" onClick="CheckTabsAssigned()"><b>ALL</b><br>
<input type="hidden" name="TabValues" value="65">
<input type="hidden" name="TabValues" value="68">
<input type="hidden" name="TabValues" value="77">
</form>
</body>
</html>

Lee
 
Howdy Lee,

I typed in the same code and it worked in mine also.
I will have to check my full code to see what it is not working.

Star to you.
I will post what my problem ended up being as soon as I fix it.

Thanks again,
ksbigfoot
 
Howdy Lee,

Thank you again for the posts.
I searched and I had two forms with the same name.
As soon as I changed the name of the one form, it worked perfectly.

Thanks again,
ksbigfoot
 
I just fixed a similar error today that I made in an ecommerce site. The credit card processing site wouldn't return the information to the originating site, and the return page gave a "Page not found" error, according to the owner of the site. What he didn't tell me was that the URL that it was supposed to go to was duplicated in the address bar, which meant that I had duplicated the form variables with identical values, which posted both values to the credit card processing form. Once I ran created an actual order, I saw what the error was and found the duplicated form variables.

So, that kind of thing happens to ALL of us at one time or other. Thanks for the star.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top