/    Sign up×
Community /Pin to ProfileBookmark

Table Hide function error

Hi, I’ve made a form for my users to edit their personal details once they are registered. This includes a section called NUS and NUS Number (National Union of Students in UK) and every time the user clicks on the NUS check button it hides/unhides the NUS Num section below it.

Now what’s wrong with it is that if the user has selected NUS it activates the checkbutton and fills out the NUS Number field, but for some reason it stops the check button from being clicked on and using the function again. This produces no errors in my Error Console in Fire Fox and the strange thing is that if the user doesn’t have NUS selected prior to this then the check button and function works fine.

Here’s the function code:

[code]
function NUSHide(f){
var mode;
<?php
if($Cont == false)
{
if($NUS == 1)
{
?>
document.Edit_Details_Form.NUS.checked = true
mode=”block”;
<?php
}
else
{
?>
if(document.Edit_Details_Form.NUS.checked == true)
{
mode=”block”;
}
else if(document.Edit_Details_Form.NUS.checked == false)
{
mode=”none”;
document.Edit_Details_Form.NUSNum.value=””;
}
<?php
}
?>
return document.getElementById(‘NUSHide’).style.display=mode;
<?php
}
else
{
?>
return false;
<?php
}
?>
}
[/code]

and here is the form code with the NUS part at the bottom:

[code]
<body onLoad=”javascript:NUSHide(document.getElementById(‘NUSHide’));”>
<div class=”MainContainer”>

<?php require(‘admin/header.inc’);
require(‘menu.inc’) ?>

<div class=”DivMain”>
<?php
if($Cont==true)
{
?>
<span class=”head2″><?php echo $MsgEdited?></span><br><br>
<a href=”my_account.php”>Back to My Account</a>
<?php

$conn = mysql_connect($Host,$Username,$Password) or die(mysql_error());
$db = mysql_select_db($Dbname, $conn);
$sql2 = “SELECT Email FROM UserAccount WHERE UserID=’$EditThisUser'”;
$rs2 = mysql_query($sql2, $conn)or die(‘Problem with query: ‘ . $sql2 . ‘<br />’ . mysql_error());
$row2 = mysql_fetch_array($rs2);

$Email = $row2[‘Email’];

mysql_close($conn);

$message=””;
$message=$message.”<html>”;
$message=$message.”<body>”;
$message=$message.”<span style=”font-family:Comic Sans MS; font-size:24pt; text-align:center; background-color:#E61732; color:white; font-weight:bold”>A&WC Clothing Line</span><br>”;
$message=$message.”This is a confirmation that you changed your account details.<br><br>”;
$message=$message.”Your new Password is: $NewPass”.”<br>”;
$message=$message.”If you were not the one responsible for changing this password then please contact The Hub immediately and we will try to sort the problem out for you.”;
$message=$message.”</body>”;
$message=$message.”</html>”;

if (mail($UserEmail,”$User – Change Account Details Confirmation – A&WC Clothing Line”,$message,”Content-Type:text/html;charset=us-ascii”)) {
$MsgChange= “Your password has been changed successfully!”;
} else {
$MsgChange= “Can’t send e-mail on this system… Doh!”;
die();
}
}
else
{
?>
<span class=”head2″>Edit Account Details Form</span><br>
<span class=”errmsg”>All fields marked with an * are required</span><br>

<?php
echo $MsgUser;
echo $MsgForename;
echo $MsgSurname;
echo $MsgCampus;
echo $MsgCourse;
echo $MsgNUSNum;
?>

<span id=”mySpan1a” class=”mySpan1a”><br></span>
<span id=”mySpan2a” class=”mySpan2a”><br></span>
<span id=”mySpan3a” class=”mySpan3a”><br></span>
<span id=”mySpan4a” class=”mySpan4a”><br></span>
<span id=”mySpan5a” class=”mySpan5a”><br></span>
<span id=”mySpan6a” class=”mySpan6a”><br></span>
<br>

<form method=”post” name=”Edit_Details_Form” action=”edit_details_form.php” onSubmit=”return Validate(this);”>

<table style=”width:auto; position:absolute;”>

<table>
<tr><td><?php echo $Err1?><span id=”mySpan1b” class=”mySpan1b”></span><span class=”head4″>Username:(Max Length 15 chars)</span><span class=”errmsg”> *</span></td>
<td><label><input type=”text” maxlength=”15″ name=”Username” value=”<?php echo $User?>”/></label></td></tr>

<tr><td><?php echo $Err2?><span id=”mySpan2b” class=”mySpan2b”></span><span class=”head4″>Forename:</span><span class=”errmsg”> *</span></td>
<td><label><input type=”text” maxlength=”15″ name=”Forename” value=”<?php echo $Forename?>”/></label></td></tr>

<tr><td><?php echo $Err3?><span id=”mySpan3b” class=”mySpan3b”></span><span class=”head4″>Surname:</span><span class=”errmsg”> *</span></td>
<td><label><input type=”text” maxlength=”20″ name=”Surname” value=”<?php echo $Surname?>”/></label></td></tr>

<tr><td><?php echo $Err4?><span id=”mySpan4b” class=”mySpan4b”></span><span class=”head4″>Campus based at: </span><span class=”errmsg”> *</span></td>
<td><label><select name=”Campus”/><option value=””>Please Select a Campus</option>

<?php
$conn = mysql_connect($Host,$Username,$Password) or die(mysql_error());
$db = mysql_select_db($Dbname, $conn);
$sql = “SELECT Campus FROM Campus ORDER BY Campus”;
$rs = mysql_query($sql, $conn) or die(mysql_error());

while($row = mysql_fetch_array($rs))
{
$Camp = $row[‘Campus’];
echo”<option value=’$Camp'”;
if($Campus == $Camp)
{echo”Selected”;}
echo”>$Camp</option>”;
}
mysql_close($conn);
?>
</select></label></td></tr>
<tr></tr>

<tr><td><?php echo $Err5?><span id=”mySpan5b” class=”mySpan5b”></span><span class=”head4″>Course Name:</span><span class=”errmsg”> *</span></td>
<td><label><input type=”text” size=”45″ name=”Course” value=”<?php echo $Course?>”/></label></td></tr>
<tr></tr>

<tr><td><span class=”head4″>NUS:</span></td>
<td><label><input type=”checkbox” name=”NUS” <?php if($NUSChk == “on”){echo”Checked”;}?> id=”NUS” onclick=”NUSHide(this)”/></label>
</td></tr>
</table>
<table width=”564″ class=”TableHidden” id=”NUSHide”>
<tr width=”340px”><td width=”266″><?php echo $Err6?><span id=”mySpan6b” class=”mySpan6b”></span><span class=”head4″>NUS Number: (18 Chars)</span></td>
<td width=”240″><label><input type=”text” maxlength=”21″ name=”NUSNum” value=”<?php echo $NUSNum?>”/></label></td></tr>
</table>
<table>
<tr><td><label><input type=”submit” style=”overflow:visible; width:auto” class=”buttonS”
name=”SubmitB” value=”Submit” onMouseOver=”OverMouse(this)”; onMouseOut=”OutMouse(this)”/>
</label>
</td></tr>
</table>
</form>
<br><br>
<a href=”my_account.php”>Back to My Account</a>
<?php
}
?>
</div>
</div>
</body>
[/code]

P.S. $Cont is only used after the form has been submitted successfully so I added that to stop the undefined function error.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 25.2008 — It is hard to judge upon the php code, as we don't know which values could have your php variables. Anyway, in debugging javascript codes we need always the HTML generated code, not the server-side language (php, asp...). Don't mention that some people here might know javascript, but not php, so they could not help you at all.
Copy linkTweet thisAlerts:
@psychofox19authorApr 25.2008 — Okay if you want to check out the site for yourself I have created a test account for you to use to check the form with.

Username: test1

Password: test1

Just login here [url="http://www.awc-clothingline.co.uk/login_form.php"]Login Page[/url] and then go here [url="http://www.awc-clothingline.co.uk/edit_details_form.php"]Edit Details form[/URL]
Copy linkTweet thisAlerts:
@psychofox19authorApr 25.2008 — Edit: Solved by self ?

I figured out that when I clicked on the button it reselected itself because of the NUS ==1 If statement, so I moved all the PHP parts to a new function on the page load and referenced the current function from the check button instead.
×

Success!

Help @psychofox19 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...