Client Side Things
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesClient Side Things

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old January 25th, 2006, 10:12 AM
mjmanuel mjmanuel is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 1 mjmanuel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
dynamic enabling/disabling of checkboxes based on value of select box

Hi! I'm trying to make a page that automatically enables/ disables checkboxes named Bold and Italic based on the value of font in the drop down box.
For example, if the user selects 'Courier New' from the drop down box and it so happens there is no italic font style for this selection, it simply disables the checkbox italic. And if there is both bold and italic fonts styles but no bold italic style, a pop-up message should say 'No bold italic style available' upon submission. The checkboxes should also be reseted (unchecked) every time a selection is made. Ive started a bit of code. Thanks. Your suggestions especially regading syntax woud be very much appreciated.

// Another question: Is it valid to mix up php and js scripts like my function below?
<SCRIPT language="JavaScript">
<!--
function verifyCheckboxes() {
font_selected = document.Form1.textfont[$i].value;
php Code:
Original - php Code
  1.  
  2.      if( font_selected != "" ) {
  3.     $fontstyle_result = mysql_query("select * from fonts where font = 'font_selected'");
  4.     $style_row = mysql_fetch_array($fontstyle_result)
  5.     if ( $style_row['Bold'.$i] == NULL ) disableCheckBox(textbold[$i]); //trying to pass this off as a variable, is this possible?
  6.       else  enableCheckBox(textbold); //trying to pass this off as a variable, is this possible?
  7.     if ( $style_row['Italic'.$i] == NULL )  disableCheckBox(textitalic[$i]); //trying to pass this off as a variable, is this possible?
  8.       else enableCheckBox(textitalic[$i]); //trying to pass this off as a variable, is this possible?
  9.      }
  10.      echo "n";
  11.      

}


//is it possible to pass the values from the functions called earlier???
function disableCheckBox (checkBox) { if (!checkBox.disabled) checkBox.disabled = true; }

function enableCheckBox (checkBox) { if (checkBox.disabled) checkBox.disabled = false; }

function fontNotAvailable () {
// if bold and italic boxes are checked but there is no bold italic font in the database
if ( ( document.form1.textbold[$i].checked && document.form1.textitalic[$i].checked ) &&
php Code:
Original - php Code
  1. ( $style_row['Bold_Italic'.$i] == NULL) 
)
box = alert("Bold Italic style not available.");
return;
}

--></script>
...
<form method="post" name="form1" action="prev_update.php" enctype="multipart/form-data" onclick="fontNotAvailable()">
php Code:
Original - php Code
  1. $result = mysql_query("select field_name, field_value, width, height, font, bold, italic, x, y, size, angle, r, g, b "
  2.             . "from template_details "
  3.             . "where del = 0 AND template_id=" . $_SESSION['template']);
  4. $rowCheck = mysql_num_rows($result);
  5.  
  6. if ($rowCheck > 0) {
  7.  $i = 1;
  8.  while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
  9.   echo "Font: <select name="textfont" . $i ."" onChange="verifyCheckboxes();" >";
  10.  while ($row1 = mysql_fetch_array($font_result)){
  11.   if (!empty($rowCheck)) { 

<option value="
php Code:
Original - php Code
  1. echo $row1['font'];
"
php Code:
Original - php Code
  1. if ($font == $row1['font'])  echo "selected"
>
php Code:
Original - php Code
  1. echo $row1['font'];
</option>
php Code:
Original - php Code
  1. } else { 

<option value="
php Code:
Original - php Code
  1. echo $row1['font'];
">
php Code:
Original - php Code
  1. echo $row1['font']
</option>
php Code:
Original - php Code
  1. }  
  2.    }
  3.    echo "</select><br />";
  4.                    
  5.    echo "Style:<input type="checkbox" sty name="textbold". $i ."" value="" . $row['bold'] . "" "; if ($row['bold'] == 1){ echo "checked";}"><b>Bold</b>&nbsp;&nbsp;
  6.    <input type="checkbox" name="textitalic". $i ."" value="" . $row['italic'] . "" "; if ($row['italic'] == 1){ echo "checked";}"> <i>Italic</i><br />";

</form>

Reply With Quote
  #2  
Old January 25th, 2006, 10:58 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: dynamic enabling/disabling of checkboxes based on value of select box

Correction on the font select part:

$font_result = mysql_query("select font from fonts order by font");
echo "Font: <select name="textfont" . $i ."" onChange="verifyCheckboxes();" >";
while ($row1 = mysql_fetch_array($font_result)) {
if (!empty($rowCheck)) { ?>
<option value="<? echo $row1['font'];?>"<? if ($font == $row1['font']) echo "selected"; ?>><? echo $row1['font'];?></option>
<? } else { ?>
<option value="<? echo $row1['font'];?>"><? echo $row1['font'];?></option>
<? }
}
echo "</select><br />";

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesClient Side Things > dynamic enabling/disabling of checkboxes based on value of select box


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT