I think I am going crazy...?

  • Thread starter The Natural Philosopher
  • Start date
T

The Natural Philosopher

Consider the function:

function edit_new()
{
document.getElementsByName("order_id")[0].value="0";
alert(document.getElementsByName("order_id")[0].value);
document.forms[0].submit();
}

In conjunction with the code

<SELECT name="order_id" style="width:150px">
<OPTION value="any" selected>Any</Option>
<OPTION value="1" >000001</OPTION>
<OPTION value="2" >000002</OPTION>
<OPTION value="3" >000003</OPTION>
</SELECT>

When it is invoked, it prints the contents of what its supposed to all
right.

But it is never 0!!!

Its 1,2,3 or 'any' depending what I select.

What fundamental errors am I making?

Its worked everywhere else!!
 
J

Jeremy

The said:
Consider the function:

function edit_new()
{
document.getElementsByName("order_id")[0].value="0";
alert(document.getElementsByName("order_id")[0].value);
document.forms[0].submit();
}

In conjunction with the code

<SELECT name="order_id" style="width:150px">
<OPTION value="any" selected>Any</Option>
<OPTION value="1" >000001</OPTION>
<OPTION value="2" >000002</OPTION>
<OPTION value="3" >000003</OPTION>
</SELECT>

When it is invoked, it prints the contents of what its supposed to all
right.

But it is never 0!!!

Its 1,2,3 or 'any' depending what I select.

What fundamental errors am I making?

Its worked everywhere else!!

Assigning a value to a select element does nothing. You need to assign
the value to one of the options.

Jeremy
 
R

RobG

The said:
Consider the function:
function edit_new()
{
document.getElementsByName("order_id")[0].value="0";
alert(document.getElementsByName("order_id")[0].value);
document.forms[0].submit();
}
In conjunction with the code
<SELECT name="order_id" style="width:150px">
<OPTION value="any" selected>Any</Option>
<OPTION value="1" >000001</OPTION>
<OPTION value="2" >000002</OPTION>
<OPTION value="3" >000003</OPTION>
</SELECT>
When it is invoked, it prints the contents of what its supposed to all
right.
But it is never 0!!!
Its 1,2,3 or 'any' depending what I select.
What fundamental errors am I making?
Its worked everywhere else!!

Assigning a value to a select element does nothing. You need to assign
the value to one of the options.

Perhaps, but the value property of the W3C DOM HTMLSelectElement is
not marked as readonly. Maybe it can be set in some UAs?

<URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-59351919 >
 
T

The Natural Philosopher

RobG said:
The said:
Consider the function:
function edit_new()
{
document.getElementsByName("order_id")[0].value="0";
alert(document.getElementsByName("order_id")[0].value);
document.forms[0].submit();
}
In conjunction with the code
<SELECT name="order_id" style="width:150px">
<OPTION value="any" selected>Any</Option>
<OPTION value="1" >000001</OPTION>
<OPTION value="2" >000002</OPTION>
<OPTION value="3" >000003</OPTION>
</SELECT>
When it is invoked, it prints the contents of what its supposed to all
right.
But it is never 0!!!
Its 1,2,3 or 'any' depending what I select.
What fundamental errors am I making?
Its worked everywhere else!!
Assigning a value to a select element does nothing. You need to assign
the value to one of the options.

Perhaps, but the value property of the W3C DOM HTMLSelectElement is
not marked as readonly. Maybe it can be set in some UAs?

<URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-59351919 >
well I muddled through the manual to

function edit_new()
{
here=document.getElementsByName("order_id")[0];
here[here.selectedIndex].value="0";
document.forms[0].submit();
}

and it worked.

What puzzles me is that
alert(document.getElementsByName("order_id")[0].value) showed any result
at all.
 
G

GArlington

Consider the function:

function edit_new()
{
document.getElementsByName("order_id")[0].value="0";
alert(document.getElementsByName("order_id")[0].value);
document.forms[0].submit();
}

In conjunction with the code

<SELECT name="order_id" style="width:150px">
<OPTION value="any" selected>Any</Option>
<OPTION value="1" >000001</OPTION>
<OPTION value="2" >000002</OPTION>
<OPTION value="3" >000003</OPTION>
</SELECT>

When it is invoked, it prints the contents of what its supposed to all
right.

But it is never 0!!!

Its 1,2,3 or 'any' depending what I select.

What fundamental errors am I making?

Its worked everywhere else!!

Consider this:
document.getElementsByName("order_id") returns an ARRAY of all
elements with that name...
therefore document.getElementsByName("order_id")[0] is the first
element of that array = your select box...
document.getElementsByName("order_id")[0].value is selected value of
the above select box...
trying to assign it to document.getElementsByName("order_id")[0].value
= "0"; as you do will have NO effect because there is NO such value in
your option list...
 
S

SAM

The Natural Philosopher a écrit :
Its worked everywhere else!!

certainly not !

the right code could be :

document.getElementsByName("order_id")[0].options[0].value="0";

or, perhaps :

document.getElementsByName("order_id")[0][0].value="0";


because :
document.getElementsByName("order_id")[0]
is the element named : "order_id"
and not its first option


function edit_new()
{
document.forms[0].order_id.options[0].value="0";
alert(document.getElementsByName("order_id")[0].value);
document.forms[0].submit();
}


function edit_new()
{
var d = document.getElementsByName("order_id")[0];
d.getElementsByTagName('option')[0].value="0";
alert(document.getElementsByName("order_id")[0].value);
document.forms[0].submit();
}
 

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,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top