how to deal whit vars in this form

N

news.wanadoo.nl

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.selected == true) {
newOpt = new Option(from.options.text, from.options.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.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
 
V

VK

news.wanadoo.nl said:
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.text
+ ' with value of ' + invRef.options.value + ' is currently ';
tmp+= (invRef.options.selected) ? 'selected' : 'not selected';
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top