Click to See Complete Forum and Search --> : Accessing a particular element
The Chancer
01-08-2004, 11:00 AM
Within a form I have numberous fields which are named sentby[], so that I can cycle through each in the results page.
However, when a checkbox is checked I would like these to become disabled.
My problem is how to relate to these elements within the form.
document.form.sentby[].disabled=true
doesn't work - and I am stumped.
Any ideas ?
Thanks,
Pittimann
01-08-2004, 11:15 AM
Hi!
Do you have a name attribute in your form tag with the value "form"? Like: <form name="form"> if not, add it. And delete the "[]" behind "sentby"...
Cheers - Pit
The Chancer
01-08-2004, 03:02 PM
Hey - the form name attribute is set to form1 - but I do need the sentby to be set as an array so that the PHP can read into it on a different page by its key...
Is there any way to refer to them dynamically in javascript by their set key ?
eg sentby[13] ? OR would I have to name them like sentby13 ?
If it is possible to reference to them by the latter, how can I append the id to the end of the element in a function.
The ideal function would be
function setdisable(thisref)
{
document.form1.sentby+thisref.disabled=true;
}
although I know that this doesn't work.. have you a suggestion for a different one ?
CHeers,
Pittimann
01-08-2004, 03:55 PM
Hi!
What type of formfields are your sentby's?
Cheers - Pit
The Chancer
01-08-2004, 04:17 PM
Select...
This is the working code at present...
(html generated through PHP)
<edit>code snipped for space...</edit>
It is supposed to make the disabled box sentby[7] active.
The array key is generated dynamically and is not guaranteed to start from 0.
Cheers,
The Chancer
01-08-2004, 04:33 PM
I have managed to get it working....
by changing the name of the sselect box to sentby7 - then referring to it via this funtion - toggles the disabled on and off...
function activate(thisone)
{
for (var i=0; i < document.ordering.length; i++) {
if(document.ordering.elements[i].name=="sentby"+thisone) {
if (document.ordering.elements[i].disabled==false)
{
document.ordering.elements[i].disabled=true;
}
else
{
document.ordering.elements[i].disabled=false;
}
}
}
}
Pittimann
01-08-2004, 04:37 PM
Hi!
You'd better remove the []'s in all your fields' name attributes!
With your example (I guess, all the 7's coming from PHP), this would work:
<div class="content" align="center">
<script language="javascript">
<!-- hide
function view(ref)
{
// Open new window
// show agent details
// give delete agent link
mywindow=window.open('../cart/viewonly.php? order_id='+ref,'newsupplier','toolbar=no,location= no,directories=no,status=yes,menubar=no,resizable=no,width=800,height=550,top=100,left=100')
mywindow.location.href = '../cart/viewonly.php?order_id='+ref;
if (mywindow.opener == null) mywindow.opener = Window;
}
function activate()
{
document.ordering.sentby7.disabled=false;
}
-->
</script>
<h4>Active Orders</h4>
<br /><br />
<table width="100%">
<tr><td colspan="4" align="left"><a href="/akwil/newsite/akwilp/admin/index.php?what=order&page=view">View Ordering Sheet</a></td><td colspan="6" align="right"><a href="/akwil/newsite/akwilp/admin/index.php?what=order&page=past">View Past Orders</a></td></tr>
<form name="ordering" method="post" action="/akwil/newsite/akwilp/admin/index.php?what=order&page=active">
<tr><td colspan="10" align="right"><input type="submit" name="submit" value="Update Orders" class="buttons" /></td></tr>
<tr class="th"><th>Delete</th><th>Company</th><th>Contact Details</th><th>Order No.</th><th>No. of Items</th><th>Date Placed</th><th>Order Placed</th><th>Order Paid</th><th>Order Sent & By</th><th>Authorised</th></tr>
<tr><td><input type="checkbox" name="delete[7]"</td><td>Administration</td><td>Akwil Administration<br />
s<br />
s</td><td align="center"><a href=java script:view(7);>7</a></td>
<td align="center">5</td>
<td align="center">08 Jan 2004 22:12:41</td>
<td align="center"><input type="text" name="placed[7]" value="Not Authorised" class="textbox" READONLY checked=true></td>
<td align="center"><input type=checkbox name=paid[7] checked=true></td>
<td align="center"><input type=checkbox name=sent[7] onclick="if(this.checked==true)activate();else document.ordering.sentby7.disabled=true">
<select name="sentby7" class="textbox" DISABLED>
<option value="">Please Select</option>
<option value="Eddie">Eddie</option>
<option value="Andrew">Andrew</option>
<option value="Operator 1">Operator 1</option>
<option value="Operator 2">Operator 2</option>
</select></td>
<td align="center"><input type=checkbox name=auth[7] checked=true DISABLED></tr>
</form>
</table>
</div>
You just have to make sure, that your PHP only writes the number(s) in your loop's instead of [number] and the PHP should also write the number into the script...
Cheers - Pit
Pittimann
01-08-2004, 04:38 PM
Hi!
Sorry, I was busy before sending my last post and didn't see yours...
Cheers - Pit
The Chancer
01-09-2004, 02:56 AM
No Worries - I needed some of the formfields in an array structure, so I could count easier without the need for hidden formfield count value.
All works fine now though - and only minor PHP changes needed...
Thanks for your time on this though.