Click to See Complete Forum and Search --> : For d best minds only ;)


ArChAnGeL2k3
03-26-2003, 03:32 PM
Hey guys,
ive got this problem, i created SELECT by using the javaScript
like this:

document.frmadd.SellType.options[0]=new Option('---');

till now everything cool,
but later when i want to check what have i selected ,
i cant (also by javascript)

if (document.frmadd.SellType.options[0].value == '---')
{
alert("kuku");

}

its doin absolutly nothing....
i tried severel stuff, but nada...
may be if ill add to the select Value when i create it above ill solve the problem, but i dont know how,
ill be very thanksfull if some one can help me with my problem,
urgent......




:confused: :confused: :confused: :confused:

khalidali63
03-26-2003, 03:58 PM
I presume that you are creating a list of options.
Your syntax to get a value from list box is wrong.

document.frmadd.SellType.options[document.frmadd.SellType.selectedIndex].value

will give you an item selected from the list.

I hope that your

new Option('---');

this line is correct too,because in reality it takes multiple parameters..

Cheers

Khalid

ArChAnGeL2k3
03-26-2003, 04:54 PM
ya i though so,
i tried already this syntex, but still nada :)
you mentiond that the

new Option('---');
have severel parametrs,
i noticed that when i checked first the create Option function
but i presumed that the sec is not importent,
may be you know what parameter i missed?
and may be there is other way to create the Option in JScript....

Thanks alot for you'r previous messege!

Jona
03-26-2003, 05:03 PM
********ing in a way what Khalid said, --- is a minus sign and a reversed increment sign (opposite of ++), so I'd suggest that you use letters. :)

What you are doing is changing the value of the selected option. If you want to change the innerText, you should use innerText = "the new option" instead of value. Because in your <OPTION> tag you have the value="" attribute.

ArChAnGeL2k3
03-26-2003, 05:18 PM
Cool,
i thnk i got it....
well i studied JScript 7 hours ago, and im kindoff new in it :D ,
but i think im starting to understand how its working,
thanks dudes, you really helped me!


if you can Jona or Khalid , link me somewhere i can study abit more about this topic, thanks, time to sleep now, its 01:18 my clock.




Good Night All!

khalidali63
03-26-2003, 09:06 PM
Originally posted by Dave Clark
........ there was nothing wrong with your syntax -- in either case or at all.
........
Dave

whatever dude...

1.Using new Options('---')
is not correct.
Correct syntax is
new Option('text ','value')


Cheers

Khalid

ArChAnGeL2k3
03-27-2003, 01:33 AM
after some studies from www.w3schools.com and experementing i came to this conclution:

Originally posted by khalidali63
whatever dude...

1.Using new Options('---')
is not correct.
Correct syntax is
new Option('text ','value')

Khalid

well actually there is nothing wrong with '---' because i created it like the text and its equale to:
<select>
<option>---<option>
</select>

but i wanted to creat this:
<select>
<option value=1>---<option>
</select>

and the way doing this is:
like you mentioned it:
new Option('text ','value')
and not like i did:
new Option('text ')

and then to use this if:
if (document.frmadd.SellType.value == 1)
{
alert("kuku");
}
so thanks its one way solving my problem, and it works just great!
:D
---------------------------------------------------------------

Dave wrote:

you used with the new Option() constructor was used to create a text property -- not a value property. Hence, your code needed to be coded this way:

if (document.frmadd.SellType.options[0].text == '---')
{
alert("kuku");
}

Yes this is another solution to my problem, in which im not using VALUE at all and just compare the text inside,
that works absolutly great!
:D
---------------------------------------------------------------
so now ive got 2 solutions, thanks to all of the Great Minds that helped me! ;)




Cya Dudes!