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

in firefox the select with value null not work good

P: n/a
if I insert a string null in a select,
it change position; why?
I insert value "" in 2nd 3th select;

<style type="text/css">
td {border:2px solid pink;};
</style>

<table border="1">

<script type="text/javascript">

var dati1=new Array();
var dati2=new Array();
var dati3=new Array();
var dati4=new Array();
var counter=0;

function invia_dati()
{ //SELECT
var select1=document.form2.sel1 ;
var select2=document.form2.sel2 ;
var select3=document.form2.sel3 ;
var select4=document.form2.sel4 ;

dati1[counter]=[1];
dati2[counter]=[""];
dati3[counter]=[""];
dati4[counter]=[1];

var aa=0;
for (var i = 0; i <1; i++)
{select1.options[aa]=new Option( dati1[i],dati1[i]);
select2.options[aa]=new Option( dati2[i],dati2[i]);
select3.options[aa]=new Option( dati3[i],dati3[i]);
select4.options[aa]=new Option( dati4[i],dati4[i]);
aa++;}

counter++;
}

</script>

<tr>
<td colspan="4">
<br />
</td>
</tr>

<form method="post" name="form1" action="" >
<tr >
<td colspan="4">
<input type="button" name="bottons" value="CERCA"
onClick="invia_dati();"/>
</td>
</tr>
<tr>
</tr>
<tr>
</tr>
</form>
<form method="post" name="form2" action="" >
<tr>
<td>
<select name="sel1" size="20" style="width:100px" multiple></select>
</td>
<td>
<select name="sel2" size="20" style="width:100px"></select>
</td>
<td>
<select name="sel3" size="20" style="width:100px"></select>
</td>
<td>
<select name="sel4" size="20" style="width:100px"></select>
</td>
<td>
<select name="sel5a" size="20" style="width:100px"></select>
</td>
<td>
<select name="sel5b" size="20" style="width:100px"></select>
</td>
<td>
<select name="sel5c" size="20" style="width:100px"></select>
</td>
<td>
<select name="sel5d" size="20" style="width:100px"></select>
</td>

</tr>

</form>
</table>
Jun 20 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Jun 20, 9:59 pm, artev <mailnotspa...@notspamm.nnwrote:
if I insert a string null in a select,
it change position; why?
I insert value "" in 2nd 3th select;
When posting code, please indent using 2 or 4 spaces and manually wrap
it at about 70 characters.
>
<style type="text/css">
td {border:2px solid pink;};
That final semi-colon is a syntax error in CSS.

</style>

<table border="1">

<script type="text/javascript">
It is always good to start with valid HTML. A script element can't be
a child of a table or tbody element in HTML 4.
>
var dati1=new Array();
var dati2=new Array();
var dati3=new Array();
var dati4=new Array();
var counter=0;

function invia_dati()
{ //SELECT
var select1=document.form2.sel1 ;
var select2=document.form2.sel2 ;
var select3=document.form2.sel3 ;
var select4=document.form2.sel4 ;
dati1[counter]=[1];
dati2[counter]=[""];
That makes the value an array of one element, whose value is an empty
string. It is not "null".
dati3[counter]=[""];
dati4[counter]=[1];

var aa=0;
for (var i = 0; i <1; i++)
{select1.options[aa]=new Option( dati1[i],dati1[i]);
select2.options[aa]=new Option( dati2[i],dati2[i]);
You are depending on the toString method of Array to return your
values, better to be more explicit:

{select1.options[aa]=new Option( dati1[i][0],dati1[i][0]);
select2.options[aa]=new Option( dati2[i][0],dati2[i][0]);

There doesn't seem much point to an array of one element, but maybe
you intend to put more values in there.

select3.options[aa]=new Option( dati3[i],dati3[i]);
select4.options[aa]=new Option( dati4[i],dati4[i]);
aa++;}

counter++;

}

</script>

<tr>
<td colspan="4">
<br />
</td>
</tr>

<form method="post" name="form1" action="" >
More invalid HTML: a form element can't be a child of a table or
tbody. A simple solution is to put the table inside the form.
<tr >
<td colspan="4">
<input type="button" name="bottons" value="CERCA"
onClick="invia_dati();"/>
</td>
</tr>
<tr>
</tr>
Yet more invalid HTML - a tr must have at least one td element inside
it.
<tr>
</tr>
</form>

<form method="post" name="form2" action="" >
....another form where it's not allowed...
<tr>
<td>
<select name="sel1" size="20" style="width:100px" multiple></select>
....and select elements must have at least one option...

Fixing your HTML plus simplifying and tidying the example will likely
fix your errors. If not, post what you end up with.
--
Rob

Jun 20 '07 #2

P: n/a
><select name="sel1" size="20" style="width:100px" multiple></select>
>
...and select elements must have at least one option...
Fixing your HTML plus simplifying and tidying the example will likely
fix your errors. If not, post what you end up with.
this is only a code for make a test; I have simplified one original
that is more complex and take datas from a db;

so it is only for make a test but is efficient for this scope;

the test is this:
first see the page html how is;

after change this
dati2[counter]=[""];
dati3[counter]=[""];
in this
dati2[counter]=[1];
dati3[counter]=[1];

and you can notice that the select are all ok how position;
make thet est with firefox and IE;

Jun 20 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.