I have a slight problem with not being able to correctly get the name of a text field from an HTML page. The code is as follows:
<file called chngrooms.php>
<?php
$query="SELECT room_name,theatre,u_shape,hollow_square,classroom,boardroom,cabaret,reception,dinner_dance,banquet FROM conf_rooms WHERE hotel_id='$hotel'";
$result=do_query($query);
print("<html><head><title>List Conference Rooms for hotel</title>
<link rel=\"stylesheet\" href=\"../../ccs.css\" type=\"text/css\">
<script language=\"Javascript1.2\">
<!--
function goNow(target)
{
if (target==1){
document.form1.action=\"chngrooms.php?page=2&store=yes&what=caps\";
document.form1.submit();
}
if (target==2){
document.form2.action=\"chngrooms.php?page=2&store=yes&what=dimensions\";
document.form2.submit();
}
if (target==3){
document.form3.action=\"chngrooms.php?page=2&store=yes&what=heights\";
document.form3.submit();
}
}
function room(roomname,targ)
{
if (targ==1) document.form1.roomselect.value=roomname;
if (targ==2) document.form2.roomselect.value=roomname;
if (targ==3) document.form3.roomselect.value=roomname;
}
function check()
{
var sure= confirm(\"Do you really want to update figures ?\");
if (sure== true)
{
return true;
}
else return false
}
warning = \"Coding by Andrew Chance\";
bV = parseInt(navigator.appVersion)
bNS = navigator.appName==\"Netscape\"
bIE = navigator.appName==\"Microsoft Internet Explorer\"
function noclick(e) {
if (bNS && e.which > 1){
alert(warning)
return false
} else if (bIE && (event.button >1)) {
alert(warning)
return false;
}
}
document.onmousedown = noclick;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (bNS && bV<5) window.onmousedown = noclick;
// -->
</script>
</head>
<body class=body>
<p /><p />
<table width=100% border=1 bordercolor=white class=table><form name=form1 method=post>
<td>Room Name</td>
<td align=center>Theatre</td>
<td align=center>U Shape</td>
<td align=center>Square</td>
<td align=center>Classroom</td>
<td align=center>Boardroom</td>
<td align=center>Cabaret</td>
<td align=center>Reception</td>
<td align=center>Dinner Dance</td>
<td align=center>Banquet</td>");
while(list($room_name, $theatre, $u_shape, $hollow_square, $classroom, $boardroom, $cabaret, $reception, $dinner_dance, $banquet)=mssql_fetch_row($result))
{
print("
<tr><td width=5%><a href=\"javascript:goNow(1);\" onclick=\"room('$room_name','1');\">$room_name</a></td>
<td align=center><input type=text name=theatre$room_name size=3 maxlength=10 class=lighttextbox value=$theatre></td>
<td align=center><input type=text name=u_shape$room_name size=3 maxlength=10 class=lighttextbox value=$u_shape></td>
<td align=center><input type=text name=hollow_square$room_name size=3 maxlength=10 class=lighttextbox value=$hollow_square></td>
<td align=center><input type=text name=classroom$room_name size=3 maxlength=10 class=lighttextbox value=$classroom></td>
<td align=center><input type=text name=boardroom$room_name size=3 maxlength=10 class=lighttextbox value=$boardroom></td>
<td align=center><input type=text name=cabaret$room_name size=3 maxlength=10 class=lighttextbox value=$cabaret></td>
<td align=center><input type=text name=reception$room_name size=3 maxlength=10 class=lighttextbox value=$reception></td>
<td align=center><input type=text name=dinner_dance$room_name size=3 maxlength=10 class=lighttextbox value=$dinner_dance></td>
<td align=center><input type=text name=banquet$room_name size=3 maxlength=10 class=lighttextbox value=$banquet></td></tr>");
}
print("<input type=hidden name=roomselect></table></form><input type=submit name=submit value=\"Update Figures\" class=buttons><p /><p />
<----file snipped----->
As you can see the input name for text are dynamically named, and when the data is passed from the database out to the page they are named with the specific room name for the values shown.
All goes well up to here.
Then when the link is clicked, the javascript bits kick in and the correct room name is passed and can be read by using
<? echo $roomselect ?>
But if you wanted the value of the text using
<? echo $theatre$roomselect ?>
doesn't work for obvious reasons ($theatre='' and $roomselect='a room name') and gives the value of just $roomselect.
The data does work as
<? echo $theatreroomname ?>
gives a true value of the information in the form.
So.. my question is this - how can you get $theatre$roomselect to give the proper value ?
Any ideas ?