By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 765 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

how to deal whit vars in this form

P: n/a
Hi,

I have found whit google this form in this group. But i'n not good in
javascript :(. I try and error normal but i only error now :P

Whit i now want to now how can i get access to the vars vis and inv. Normal
when i submit a form then is see something link
formhandler?vis=somthing&inv=something. But i dont see that in this form.
I want the use data form this form to set it in a databse whit php. I cant
get use nog $_GET['vis'] is wil give nothing.

Is there someone who can helpen me ?

The script:
<SCRIPT LANGUAGE="JavaScript"> // Code to move the seletions
function moveSelected(from, to) {
var fl = from.length;
var tl = to.length;
var i;
var n;
var newOpt;
// if there is a blank set <option></option>, get rid of it
if(tl == 1 && to.options[0].text == "") {
to.options[0] = null;
document.recalc(true);
tl--;
}
var index = 0;
for(i = 0; i < fl; i++) {
if(from.options[i].selected == true) {
newOpt = new Option(from.options[i].text, from.options[i].text,
false,
false);
index = findIndex(newOpt, to);
to.options.add(newOpt);
for(n = tl; n > index; n--) {
to.options[n].text = to.options[n - 1].text;
}
tl++;
to.options[index].text = newOpt.text;
from.options[i--] = null;
document.recalc(true);
fl--;
}
}
return;
}
function findIndex(insert, toList) {
var k;
for(k = 0; k < toList.length; k++) {
if( sorted(insert, toList.options[k]) == false) {
break;
}
}
if(k < 0) {
k = 0;
}
return k;
}
/* NOTE: This function will select all options in a select box.
This is
is often needed in conjunction with the moveSelected function.
Moving
an option into a "selected" box won't send it along when the form
is
submitted unless that box has all options selected.
*/
function doSelects(formElement) {
var i;
for(i = 0; i < formElement.length; i++) {
formElement.options[i].selected = true;
}
return;
}
function sorted(one, two) {
var oneString = one.text;
var twoString = two.text;
if(oneString > twoString) {
return true;
}
else {
return false;
}
}
</SCRIPT>
<form action=test.php method="get">
<table align=center width=400 style="font-family:arial; font-size:9pt;
color:purple;">
<tr>
<td>
<ul>
<li>Use the buttons below to add and remove
suppliers
<li>Hold down shift and use the mouse to select
multiple supliers
<li>Submit changes by clicking 'Update Database'
</ul>
</td>
</tr>
</table>
<p align="center"></p>
<table border=2 bordercolor=purple align=center><tr><td align=center>
<table align=center border=0 bgcolor=#f5f5f5 cellspacing=8
cellpadding=8>
<tr>
<td align=center style="font-family:arial; font-size:9pt;
color:purple;">Unavailable Suppliers</td>
<td width=50 align=center>&nbsp;</td>
<td align=center style="font-family:arial; font-size:9pt;
color:purple;">Available Suppliers</td>
</tr>
<tr>
<td align=center>
<select multiple style="width:150; color:purple;
background:#f5f5f5;"
size=10 id="inv" name="inv">
<option value=1>Supplier 1</option>
<option value=2>Supplier 2</option>
<option value=3>Supplier 3</option>
<option value=4>Supplier 4</option>
<option value=5>Supplier 5</option>
</select></td>
<td align=center> <!-- ################ BUTTONS ############## -->
<table align=center width=100% height=100% border=0 cellspacing=4
cellpadding=4>
<tr>
<td align=center>
<input onClick="moveSelected(inv,vis)"
title="Make selected
suppliers available" type="button" style="BACKGROUND-COLOR: #660066;
COLOR: #ffcc00; width:50;" name="add_to_inv" value=" > "><BR>
<input onClick="doSelects(inv);moveSelected(inv, vis) "
title="Make all suppliers available" type="button"
style="BACKGROUND-COLOR: #660066; COLOR: #ffcc00; width:50;"
name="add_to_vis" value=" >> "><BR>
</td>
</tr>
<tr>
<td align=center>
<input onClick="moveSelected(vis, inv)"
title="Make selected
suppliers unavailable" type="button" style="BACKGROUND-COLOR: #660066;
COLOR: #ffcc00; width:50;" name="add_to_vis" value=" < "><BR>
<input
onClick="doSelects(vis,inv);moveSelected(vis, inv)"
title="Make all suppliers unavailable" type="button"
style="BACKGROUND-COLOR: #660066; COLOR: #ffcc00; width:50;"
name="add_to_inv" value=" << "><BR>
</td>
</tr>
</table>
<td align=center>
<select multiple style="width:150; color:purple;
background:#f5f5f5;"
size=10 id="vis" name="vis">
<option value=6>Supplier 6</option>
<option value=7>Supplier 7</option>
<option value=8>Supplier 8</option>
<option value=9>Supplier 9</option>
<option value=10>Supplier 10</option>
</select>
</tr>
<tr>
<td align=center colspan=3><input type=submit name=submit
value="Update Database" style="BACKGROUND-COLOR: #660066; COLOR:
#ffcc00; width:200;"></td>
</tr>
</table></tr></td></table><form>
Greets Wouter
Feb 19 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
VK

news.wanadoo.nl wrote:
Hi,

I have found whit google this form in this group. But i'n not good in
javascript :(. I try and error normal but i only error now :P

Whit i now want to now how can i get access to the vars vis and inv. Normal
when i submit a form then is see something link
formhandler?vis=somthing&inv=something. But i dont see that in this form.
I want the use data form this form to set it in a databse whit php. I cant
get use nog $_GET['vis'] is wil give nothing.


"inv" and "vis" are not JavaScript variable: these are names of two
form elements (select lists). It is bad that you did not give a name to
your form. Presuming that this is the only form on your page, you get
references to these elements by:

var invRef = document.forms[0].elements['inv'];
var visRef = document.forms[0].elements['vis'];

The further depends on what do you want to do with them. Say you want
to know all selected options in multiple select list:

var tmp = '';
for (var i=0; i<invRef.options.length; i++) {
tmp = 'Option ' + invRef.options[i].text
+ ' with value of ' + invRef.options[i].value + ' is currently ';
tmp+= (invRef.options[i].selected) ? 'selected' : 'not selected';
}

Feb 20 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.