471,055 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,055 software developers and data experts.

deleting items from droplist

TJS
if country other than us is selected, I want to show only wire transfer as
payment option.
can someone help me get this "deleteoptions" code to work ?

==========================================
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">

<script language="javascript">
function setPayment(obj) {
var indx = obj.options[obj.selectedIndex].value;
if (indx != "US") {
var obj2 = document.orderform.idPayment;
deleteOptions(obj2);
}
}

function deleteOptions(obj2) {
while (obj2.options.length>1) {
deleteIndex=obj2.options.length-1;
//alert(obj2.options[deleteIndex].value );
if (obj2.options[deleteIndex].value != "11") {
obj2.options[deleteIndex]=null;
}
}
}

</script>
<form METHOD="POST" name="orderform" ">
<TABLE BORDER="0" CELLPADDING="0" WIDTH="590" align="left">
<TD WIDTH="202"> Country </TD>
<TD WIDTH="393">
<SELECT name="countryCode" value="US" onChange="setPayment(this);" >
<OPTION VALUE="US" SELECTED >UNITED STATES( US)</OPTION>
<OPTION VALUE="AD" >ANDORRA( AD)</OPTION>
<OPTION VALUE="AE" >UNITED ARAB EMIRATES( AE)</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<TD colspan="2"><b>Payment </b></TD>
</TR>
<TR>
<TD width="202"> Pay with </TD>
<TD width="393">
<select name="idPayment" size="1">
<option value="5">Credit Card</option>
<option value="9">Check </option>
<option value="11">Wire Transfer</option>
</select>
</TD>
</TR>
</table>
</form>

Jul 23 '05 #1
3 1346


This might arguably be confusing, popping items in & out of a list box.
Users are more accustomed to disablement...

function setPayment(obj)
{
var v = obj.options[obj.selectedIndex].value,
bUS = (v == "US"),
bWire,
r = 0,
rad,
rads = obj.form.elements.idPayment;
while (rad = rads[r++])
{
bWire = (rad.value == '11');
rad.disabled = (!bUS && !bWire);
rad.checked = (!bUS && bWire);
}
}

onload = function()
{//keep things in sync
var el;
if (el = document.getElementById('countryCode'))
el.onchange();
}

<TD WIDTH="393">
<SELECT id="countryCode" name="countryCode" value="US"
onChange="setPayment(this)">
<OPTION VALUE="US" SELECTED="selected" >UNITED STATES(US)</OPTION>
<OPTION VALUE="AD" >ANDORRA(AD)[wire transfer only]</OPTION>
<OPTION VALUE="AE" >UNITED ARAB EMIRATES(AE)[wire transfer
only]</OPTION>
</SELECT>
</TD>
</TR>
<TR>
<TD colspan="2"><b>Payment </b></TD>
</TR>
<TR>
<TD width="202"> Pay with </TD>
<TD width="393">
<label for="iP1"><input id="iP1" type="radio" name="idPayment"
value="5"> Credit card</label>
<label for="iP2"><input id="iP2" type="radio" name="idPayment"
value="9"> Check</label>
<label for="iP3"><input id="iP3" type="radio" name="idPayment"
value="11"> Wire transfer</label>
</TD>

Always back up at the server, of course.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #2
TJS wrote:
if country other than us is selected, I want to show only wire transfer as
payment option.
can someone help me get this "deleteoptions" code to work ?

[...]

As an alternative, why not make the payment methods into radio buttons?
Then users can only select one, and you can easily disable those you
don't want them to check.

If any country other than US is chosen, disable "Credit" and "Check"
and select "Wire transfer".
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Payment</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script language="javascript">
function setPayment(f,v) {
var ele = f.elements;
for (var i=0; i<ele.length; i++) {
if (ele[i].type == "radio") {
if(v != 'US') {
if (ele[i].value == "11" ) {
ele[i].checked = true;
} else {
ele[i].checked = false;
ele[i].disabled = true;
}
} else {
ele[i].disabled = false;
}
}
}
}
</script>
</head>
<body style="font-family: sans-serif;">
<form METHOD="POST" name="orderform" action="">
<table border="0">
<tr>
<td>Country</td>
<td>
<select name="countryCode" value="US" onChange="
setPayment(this.form,this.value);">
<option value="US" selected>United States (US)</option>
<option value="AD">Andorra (AD)</option>
<option value="AE">United Arab Emirates (AE)</option>
</select></label>
</td>
</tr><tr>
<td colspan="2" style="border-bottom: 1px solid blue;
padding: 5 0 0 0;"><b>Payment Method</b></td>
</tr><tr>
<td valign="top" style="padding: 3 0 0 0;">Pay with</td>
<td>
<input type="radio" name="payMethod" value="5"
checked="checked">Credit Card<br>
<input type="radio" name="payMethod" value="9">Check<br>
<input type="radio" name="payMethod" value="11">Wire Transfer<br>
<input type="reset" onclick="
setPayment(this.form,'US');this.blur();">
<td>
</tr>
</table>
</form>
</body>
</html>

Cheers.
--
Rob
Jul 23 '05 #3
TJS
good help, thanks all ..
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Amit Kela | last post: by
2 posts views Thread by KraftDiner | last post: by
1 post views Thread by jez123456 | last post: by
4 posts views Thread by TJS | last post: by
5 posts views Thread by TJS | last post: by
8 posts views Thread by Christian Bruckhoff | last post: by
reply views Thread by leo001 | last post: by

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.