473,657 Members | 2,604 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Looping and Removing all options

Hi

Is this correct to clear select items?

function(sel){
var selected = sel.options[w].text;
var name=sel.name;

(i=1; i<sel.length=0, i++){
sel.options.len gth=0;}

if(var name="test"){
for (i=0;i< test;i++)
..
..
..}

<select name="test" id="test" onchange="updat eOrder(this);">

<option>0</option>
<option>1</option>
<td bgcolor="#FFE9B B" class="borderBR "><select name="example" size="4"
multiple="multi ple" id="example"<op tion>0</option>

Greg

Aug 26 '06 #1
5 1794

Just sel.length=0 will do all :) .

Danny

Aug 26 '06 #2
Danny wrote on 26 aug 2006 in comp.lang.javas cript:
Just sel.length=0 will do all :) .
A fine answer.

A pity, Danny,
many of us do not know
what you are talking about,
if you do not quote on usenet.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 26 '06 #3

Danny wrote:
Just sel.length=0 will do all :) .

How about when you have:
function(test){

}
<form>
<select name=s1 multiple=true size=5 onchange(this)>
<option>0
<option>1
<option>2
<option>3
<option>4
<option>5
</select>
and your writing to:
<select name=s2 multiple=true size=5 onchange(this)>
<option </option>

and every time you make an option it writes to s2, and if the user
changes their mind instead of writing the new option under the old one,
you write on top of the old one.

Aug 26 '06 #4

Gregc. wrote:
Danny wrote:
Just sel.length=0 will do all :) .


How about when you have:
function(test){

}
A function that does nothing, and isn't called at all?

<form>
<select name=s1 multiple=true size=5 onchange(this)>
Did you mean:

<select ... onchange="test( this)">

Using onchange with select elements is known to produce unwelcome
sideeffects, I don't think it's the right solution here.

<option>0
<option>1
<option>2
<option>3
<option>4
<option>5
</select>
and your writing to:
<select name=s2 multiple=true size=5 onchange(this)>
<option </option>

and every time you make an option it writes to s2, and if the user
changes their mind instead of writing the new option under the old one,
you write on top of the old one.
If you post working code, or at least something that demonstrates what
you are trying to do, you might get better responses. If you can't
write the code, write a clear description of what you are trying to do.
--
Rob

Aug 26 '06 #5
oz****@iinet.ne t.au wrote:
If you post working code, or at least something that demonstrates what
you are trying to do, you might get better responses. If you can't
write the code, write a clear description of what you are trying to do.
--
Rob
Hi Rob

Attached is the code that I am currently trying to get to work.

<html>

<head>

<script type="text/javascript">

function updateOrder(obj ) {

var i;
var vehicleType=obj .name;
var w=obj.selectedI ndex;
var selected_text = obj.options[w].text;
var car1=document.g etElementById(" carType");
var qty1=document.g etElementById(" orderQty");
var qty2=parseInt(o bj.options[w].text);
var orPrice=documen t.getElementByI d("orderPrice") ;
var holdern_Price = 10;
var ford_Price = 20;
var del=50;
var del_c=10;
var delCost1=0;
var delCost2=0;
var totalDel=0;
var final_total=0;
var Holden_Total=0;
var Ford_Total=0;

//Clears out all options
for (i=0 ;i<document.for m1[0].len.length ;i++)
{
obj.length=0
}

//Holden

if(vehicleType= ="Holden"){

for (i=0;i< vehicleType;i++ )
car1.options[car1.options.le ngth]=new Option("Holden" );
qty1.options[qty1.options.le ngth]=new Option(selected _text);
orPrice.options[orPrice.options .length]=new Option(holdern_ Price);
Holden_Total = holdern_Price*q ty2;
var delCost1=del+(d el_c*qty2);

}

//Ford

else if(vehicleType= ="Ford"){
for(i=0;i< vehicleType;i++ )
car1.options[car1.options.le ngth]=new Option("Ford");
qty1.options[qty1.options.le ngth]=new Option(selected _text);
orPrice.options[orPrice.options .length]=new Option(ford_Pri ce);
Ford_Total= ford_Price*qty2 ;
var delCost2=del+(d el_c*qty2)

}

// total figure
final_total=Hol den_Total+Ford_ Total+delCost1+ delCost2
document.getEle mentById("price Products").valu e=Holden_Total+ Ford_Total;
// changed
document.getEle mentById("price Shipping").valu e=delCost1+delC ost2;
document.getEle mentById("price Total").value=f inal_total;
}

</script>
</head>
</script>
</head>
<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0 "
style="text-align:center">
<form name="form1" method="post" action="" onsubmit="">
<select name="Holden" id="Holden" onchange="updat eOrder(this);">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<select name="Ford" id="Ford" onchange="updat eOrder(this);">
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</form>
<td bgcolor="#FFE9B B" class="borderBR "><select name="Type of Car"
size="10" id="carType">
<option>Car Ordered</option>
</select </td>
<td bgcolor="#FFE9B B" class="borderBR "><select name="orderQty" size="4"
multiple="multi ple" id="orderQty">
<option>0</option>
<td bgcolor="#FFE9B B" class="borderB" ><select name="orderPric e"
size="4" multiple="multi ple" id="orderPrice" >
<option>$0.00 </option>

</select></td>
</tr>
<td bgcolor="#FFE9B B">&nbsp;</td>
<td align="right" bgcolor="#DFAF6 F"
class="borderBR "><strong>Produ ct Total: </strong></td>
<td bgcolor="#FFE9B B" class="borderB" ><input
name="priceProd ucts" type="text" id="priceProduc ts" size="8" /></td>
</tr>
<td align="right" bgcolor="#DFAF6 F" class="borderBR "><strong>Shipp ing
Costs: </strong></td>
<td bgcolor="#FFE9B B" class="borderB" ><input
name="priceShip ping" type="text" id="priceShippi ng" size="8" /></td>
</tr>
<td bgcolor="#FFE9B B">&nbsp;</td>
<td align="right" bgcolor="#DFAF6 F"
class="borderBR "><strong>O rder Total: </strong></td>
<td bgcolor="#FFE9B B" class="borderB" ><input
name="priceTota l" type="text" id="priceTotal " size="8" /></td>
</tr>
</body>

</html>

Greg

Aug 26 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4052
by: kaptain kernel | last post by:
i've got a while loop thats iterating through a text file and pumping the contents into a database. the file is quite large (over 150mb). the looping causes my CPU load to race up to 100 per cent. Even if i remove the mysql insert query and just loop through the file , it still hits 100 per cent CPU. This has the knock on effect of slowing my script down so that mysql inserts are occuring every 1/2 second or so.
4
34611
by: Kelvin | last post by:
Dear All, Please help. Same as subject !!!
24
4370
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what we covered was within the last week of the class and all self taught. Our prof gave us an example of a Java method used to remove elements from an array: public void searchProcess() { int outIt=0;
8
2161
by: Matt Kruse | last post by:
Using the latest version of Opera 8.5, this test case: -------------------------------------------------------- <select name="sel" multiple="true" size="3"> <option value="option1" selected>option1</option> <option value="option2" selected>option2</option> <option value="option3" selected>option3</option> </select> <input type="button"
13
5018
by: JayCallas | last post by:
I know this question has been asked. And the usual answer is don't use cursors or any other looping method. Instead, try to find a solution that uses set-based queries. But this brings up several questions / senarios: * I created several stored procedures that take parameters and inserts the data into the appropriate tables. This was done for easy access/use from client side apps (i.e. web-based).
2
2176
by: LayneMitch via WebmasterKB.com | last post by:
I'm trying to add more form options depending on what you chose and then remove the form options if the main option is deselected. The latter is what I'm having the problem with. I only need suggestions on the checkbox options, not the radio options. Depending on what advice I get for the checkbox options, I can alter the code for the radio options. The form code is very long so I'll only post the problem area and it's related...
1
1994
by: Robocop | last post by:
Having just started using C again after some years off, i've been stumped by a problem i think someone more experienced could probably solve pretty easily. I have these 4 objects (vectors), and i want to find a combination of these 4 objects into two pairs, where the sum of a specific attribute of each vector in each pair comes closest to some base value. So all i want to do is run through the permutations of these 4 objects and find the...
9
7653
by: Chris | last post by:
How do I amend the following code to skip removing the first option in my dropdown list i.e. I want the first option "Please select..." to stay? while (document.getElementById("mycombo").childNodes.length 0) { document.getElementById("mycombo").removeChild(document.getElementById("mycombo").childNodes) } Many thanks,
9
1861
by: Rick W. | last post by:
<script> function filldims() { var objSelect = document.getElementById("id_intwidth"); objSelect.options.length = 0; for(var i = 20; i < 31; i++) { var objOption = document.createElement("option");
0
8303
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8821
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8723
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8602
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1941
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.