thetrend
11-02-2008, 05:18 AM
this may have a totally simple solution, but I'm a newb when it comes to JavaScript (I'm more PHP-oriented).
here are my codes, as you can tell I did not write them, seeing as I have very little knowledge of javascripting.
the javascript:
<script type="text/javascript">
//<![CDATA[
<!--
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Nannette Thacker | http://www.shiningstar.net */
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
return "Uncheck All";
} else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
return "Check All";
}
}
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Robin Jones :: http://www.robinjones1.freeuk.com */
function jumpBox(list) {
location.href = list.options[list.selectedIndex].value
}
-->
//]]>
</script>
the html:
First, the checkboxes:
<form name="myform" action="" method="post">
<table>
<tr>
<td><strong>Make a selection</strong>
<br />
<input type="checkbox" name="list" value="1" />Java
<br />
<input type="checkbox" name="list" value="2" />JavaScript
<br />
<input type="checkbox" name="list" value="3" />ASP
<br />
<input type="checkbox" name="list" value="4" />HTML
<br />
<input type="checkbox" name="list" value="5" />SQL
<br />
<br />
<input type="button" value="Check All" onclick="this.value=check(this.form.list)" /></td>
</tr>
</table>
</form>
<br />
and the dropdown:
<form>
<select>
<option selected="selected">
Select a page
</option>
<option value="demo1.html">
Page One
</option>
<option value="demo2.html">
Page Two
</option>
<option value="demo3.html">
Page Three
</option>
</select> <input type="button" value="Go" onclick="jumpBox(this.form.elements[0])" />
</form>
I'd like to consolidate them into one form, and on a sidenote, I'd like to have innerhtml $number of items selected; I know how it works, but like I said, since I'm a JS newb, I don't know how to write it. xP
one reason why I'd like to consolidate the forms is that I'm writing a private message system in php and I was going to use the option values as the form action url.
this is how I was going to format it:
<form> <table width="90%" align="center" border="0" style="border: 0">
<tr>
<th style="width: 50%; text-align: left"> Letter</th>
<th style="width: 20%">Date</th>
<th style="width: 18%">Status</th>
<th style="width: 12%">Select</th>
</tr>
<?php
while($mail = mysql_fetch_object($getmail)) {
$status = $mail->status;
if($status == '0') {
$title = "<b>".$mail->title."</b>";
$status = "Unopened";
} elseif($status == '1') {
$title = "<em>".$mail->title."</em>";
$status = "Read";
} elseif($status == '2') {
$title = $mail->title;
$status = "Replied";
}
?>
<tr>
<td style="text-align: left">
<a href="/mail/view.php?id=<?php echo $mail->id ?>"><?php echo $title ?></a>
from <a href="/profile.php?user=<?php echo $mail->sender ?>"><?php echo $mail->sender ?></a>
</td>
<td><?php echo $mail->sentdate ?></td>
<td><?php echo $status ?></td>
<td><input type="checkbox" name="check" id="letter[<?php echo $mail->id ?>]" value="<?php echo $mail->id ?>" /></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" style="text-align: right">
<span id="msg"></span><span id="link" title="Only works if there's more than one!"><a href="javascript:selectAll()">Select all</a></span>
<select>
<option value="">Select a page</option>
<option value="?action=archive">Archive</option>
<option value="?action=delete">Delete</option>
</select>
<input style="margin: 0; padding: 0" type="button" value="Go" onclick="jumpBox(this.form.elements[0])" /></form>
</td>
</tr>
</table>
or at least, that's how my old code was, but it confused me (the php is mine, the javascript bits are all from random resources, but I'd rather start over with help. =]
merci to anyone who can help ^_^
here are my codes, as you can tell I did not write them, seeing as I have very little knowledge of javascripting.
the javascript:
<script type="text/javascript">
//<![CDATA[
<!--
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Nannette Thacker | http://www.shiningstar.net */
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;
}
checkflag = "true";
return "Uncheck All";
} else {
for (i = 0; i < field.length; i++) {
field[i].checked = false;
}
checkflag = "false";
return "Check All";
}
}
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Robin Jones :: http://www.robinjones1.freeuk.com */
function jumpBox(list) {
location.href = list.options[list.selectedIndex].value
}
-->
//]]>
</script>
the html:
First, the checkboxes:
<form name="myform" action="" method="post">
<table>
<tr>
<td><strong>Make a selection</strong>
<br />
<input type="checkbox" name="list" value="1" />Java
<br />
<input type="checkbox" name="list" value="2" />JavaScript
<br />
<input type="checkbox" name="list" value="3" />ASP
<br />
<input type="checkbox" name="list" value="4" />HTML
<br />
<input type="checkbox" name="list" value="5" />SQL
<br />
<br />
<input type="button" value="Check All" onclick="this.value=check(this.form.list)" /></td>
</tr>
</table>
</form>
<br />
and the dropdown:
<form>
<select>
<option selected="selected">
Select a page
</option>
<option value="demo1.html">
Page One
</option>
<option value="demo2.html">
Page Two
</option>
<option value="demo3.html">
Page Three
</option>
</select> <input type="button" value="Go" onclick="jumpBox(this.form.elements[0])" />
</form>
I'd like to consolidate them into one form, and on a sidenote, I'd like to have innerhtml $number of items selected; I know how it works, but like I said, since I'm a JS newb, I don't know how to write it. xP
one reason why I'd like to consolidate the forms is that I'm writing a private message system in php and I was going to use the option values as the form action url.
this is how I was going to format it:
<form> <table width="90%" align="center" border="0" style="border: 0">
<tr>
<th style="width: 50%; text-align: left"> Letter</th>
<th style="width: 20%">Date</th>
<th style="width: 18%">Status</th>
<th style="width: 12%">Select</th>
</tr>
<?php
while($mail = mysql_fetch_object($getmail)) {
$status = $mail->status;
if($status == '0') {
$title = "<b>".$mail->title."</b>";
$status = "Unopened";
} elseif($status == '1') {
$title = "<em>".$mail->title."</em>";
$status = "Read";
} elseif($status == '2') {
$title = $mail->title;
$status = "Replied";
}
?>
<tr>
<td style="text-align: left">
<a href="/mail/view.php?id=<?php echo $mail->id ?>"><?php echo $title ?></a>
from <a href="/profile.php?user=<?php echo $mail->sender ?>"><?php echo $mail->sender ?></a>
</td>
<td><?php echo $mail->sentdate ?></td>
<td><?php echo $status ?></td>
<td><input type="checkbox" name="check" id="letter[<?php echo $mail->id ?>]" value="<?php echo $mail->id ?>" /></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" style="text-align: right">
<span id="msg"></span><span id="link" title="Only works if there's more than one!"><a href="javascript:selectAll()">Select all</a></span>
<select>
<option value="">Select a page</option>
<option value="?action=archive">Archive</option>
<option value="?action=delete">Delete</option>
</select>
<input style="margin: 0; padding: 0" type="button" value="Go" onclick="jumpBox(this.form.elements[0])" /></form>
</td>
</tr>
</table>
or at least, that's how my old code was, but it confused me (the php is mine, the javascript bits are all from random resources, but I'd rather start over with help. =]
merci to anyone who can help ^_^