Hello,
I'm re-posting this with correct highlighting on where the problem is occuring.
How do I hide a form when a link is clicked?
Basically I have 2 functions, cr_card_disp1 and cr_card_disp2. When the <Add New Credit Card> link is clicked, the form in cr_card_disp2 should be displayed and the form in cr_card_disp1 should be hidden.
However, when I click Add New Credit Card link the form in cr_card_disp2 is getting displayed and the form in cr_card_disp1 is still visible.
The setVisibility javascript function is not working.
The following is my code:
<script language="javascript" type="text/javascript">
[COLOR="blue"]function setVisibility()[/COLOR]{
var frm_element = document.getElementById('cr_card_disp1_frm');
frm_element.style.display='none';
}
</script>
if (@$_GET['action']=="add_cr_card")
{$_SESSION['add_cr_card_flag']="true";
echo "add credit card flag: ".$_SESSION['add_cr_card_flag'];
cr_card_disp2();
}
[COLOR="blue"]function cr_card_disp1() [/COLOR]//CUST WITH RECORD IN DATABASE
{
echo $_SESSION['cust_id'];
$sql="select cr_card, cr_no, exp_mth, exp_yr from credit_card where cust_id=".$_SESSION['cust_id']."";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result)>0) //OLD CUST WITH CR_CARD DETAILS IN DB
{//echo "number of records ".mysql_num_rows($result);
echo "<div id = 'form_general'>";
?>
<form id='cr_card_disp1_frm' action='confirm.php' method='post'>
<?php
echo "<div class='form_label1' style='top:70%;'>Payment</div>";
echo "<div class='form_element' style='top:70%; vertical-align:middle;'>";
echo "<select id='cr_card_details' name='cr_card_details' >";
$str_asterisk = "***********";
while ($row = mysql_fetch_array($result))
//for (j=0; $row=mysql_fetch_array($result); j++)
{
if ((@$_SESSION['cr_card'] == $row['cr_card']) &&
($_SESSION['cr_no'] == $row['cr_no']) &&
($_SESSION['exp_mth'] == $row['exp_mth']) &&
($_SESSION['exp_yr'] == $row['exp_yr']))
{ echo "<option selected>".$_SESSION["cr_card"]." ".$str_asterisk.$_SESSION['cr_no']." exp ".$_SESSION['exp_mth']."/".$_SESSION['exp_yr']."</option>";
}
else
echo "<option>".$row["cr_card"]." ".$str_asterisk.$row['cr_no']." exp ".$row['exp_mth']."/".$row['exp_yr']."</option>";
}//END OF WHILE STMT
echo "</select>";
echo "</div>";
echo "<input type='submit' id='Continue' value='Continue' style='position:absolute;right:60%;margin-top:7px;'>";
echo "</form>";
echo "</div>";
[COLOR="Red"]echo "<a href='cr_card_disp.php?action=add_cr_card' onclick=\"javascript:setVisibility()\" style='position:absolute;right:45%;margin-top:7px;'>Add New Credit Card</a>";[/COLOR]
}//END OF IF (MYSQL_NUM_ROW)
else //OLD CUST WITHOUT CR_CARD DETAILS IN DB
cr_card_disp2();
}//END OF CR_CARD_DISP1()
[COLOR="Blue"]function cr_card_disp2()[/COLOR]{//echo "cr_card_disp2";
$sql = "Select cr_card from credit_card_det";
$result = mysql_query($sql) or die(mysql_error());
?>
<div style="position:absolute;top:75%;left:-5%;margin:0;padding:0;width:100%;height:30%;">
<form action="confirm.php" method="post">
<?php
echo "<div class='form_label1' style='left:7%;'>Payment</div>";
echo "<div class='form_element' style='right:40%; vertical-align:middle;'>";
echo "<select name='cr_card'>";
while ($row = mysql_fetch_array($result))
{//if (isset($_SESSION['cr_card']) || isset($_POST['cr_card']))
//echo $row["cr_card"];
if (@$_SESSION['cr_card'] == $row["cr_card"] || @$_POST['cr_card']==$row["cr_card"])
echo "<option selected>".$row["cr_card"]."</option>";
else
echo "<option>".$row["cr_card"]."</option>";
}
echo "</select>";
?>
Card Number: <input type="text" name="cr_no" maxlength="16" value="<?php
if (isset($_POST['cr_no']))
echo $_POST['cr_no'];
else if (isset($_SESSION['complete_cr_no']))
echo $_SESSION['complete_cr_no'];
?>">
Expiration Date:
<select name="exp_mth">
<?php for ($mth=1; $mth<=12; $mth++)
{ if ($mth < 10)
{if (@$_SESSION['exp_mth']=="0".$mth || @$_POST['exp_mth']=="0".$mth)
echo "<option selected>"."0".$mth."</option>";
else
echo "<option>"."0".$mth."</option>";
}
else
{if (@$_SESSION['exp_mth']==$mth || @$_POST['exp_mth']==$mth)
echo "<option selected>".$mth."</option>";
else
echo "<option>".$mth."</option>";
}
}
?>
</select>
<?php
$today = getdate();
?>
<select name="exp_yr">
<?php
for ($yr=$today["year"]; $yr<=$today["year"]+20; $yr++)
//if (isset($_SESSION['exp_yr']) || isset($_POST['exp_yr']))
{ if (@$_SESSION['exp_yr']==$yr || @$_POST['exp_yr']==$yr)
echo "<option selected>".$yr."</option>";
else
echo "<option>".$yr."</option>";
}
?>
</select>
<input type="submit" value="Continue Checkout" style="position:absolute;top:0;right:-15%;"/>
</form>
</div>
<?php
}//END OF CR_CARD_DISP2()
?>
thank you in advance