#1 (permalink)  
Old 05-02-2007, 02:13 PM
schelly's Avatar
Registered User
 
Join Date: May 2007
Location: Sunny San Diego
Posts: 1
Disable field2 select if field1 select value fails test

Hello and thank you for any help you can give me. I'm using a php billing script that allows me to create order forms. Because it is scripted, I am limited in the controls I have on form fields and javascript functions. However, the author was kind enough to provide areas in which we can enter html attributes, pre-field and post-field html boxes, and a "javascript" code box that we can enter stuff into that will show up in between the <head> and </head> tags of the order page.

I am managing a site for a not-for-profit organization that accepts "sponsorships" from its members. Those who give a $25 or $50 sponsorship amount will receive mention on the sponsor page, and those who give $100 or $200 amounts are eligible to buy discounted ad banner rotations on the site. Here's what I have done so far.

On my order page I have created the select list for sponsorship levels. The "value" of each level is the dollar amount of that level. So there's a value of 25, a value of 50, a value of 100 and a value of 200 respective of each sponorship level. I then created a second select list for rotating banner ads. Now I want to provide some control.

If a person selects the $25 or $50 level, I want the second select list to be grayed out. If a person selects the $100 or $200 level, I want the second select list to be available. The original programmer of this billing script provided me with the following instructions:

Code:
Suppose you have a selectbox field called field1 attached to a product. You want that product to be a prerequisite for allowing a 2nd product to be ordered. The 2nd product is associated with another selectbox on the form, called field2.

On field2's HTML attributes, enter the following:

disabled="disabled"

That will cause field2 to be greyed out by default (it is up to the browser how a disabled control is displayed - some don't grey things out, just make them inoperable). Now to enable field2 when field1 is checked:

On field1's HTML attributes, enter the following:

onclick="field1_click();"

On the 'advanced' tab of the form, enter the following in the 'Javascript Functions' area:

function field1_click()
{
  if (order_form.field1.options[order_form.field1.selectedIndex].value >= 100)
  {
    order_form.field2.disabled = false;
  }
  else
  {
    order_form.field2.selectedIndex = -1;
    order_form.field2.disabled = true;
  }
}
Unfortunately this isn't working. I'm wondering if anybody sees some kind of glaring error here that can help figure this thing out?

Thanks again for any help anybody can provide...
Schelly
Reply With Quote

  #2 (permalink)  
Old 05-06-2007, 08:11 AM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,445
I believe your problem is coming from the fact that JavaScript interprets all form values (to the best of my knowledge) as string variables. In order to use mathematical functions such as ">=", you need to be working with an integer variable. Therefore, try adding parseInt() around the call for the form field's value. Therefore, it would look like:
Code:
var myNum = order_form.field1.options[order_form.field1.selectedIndex].value;
if (paresInt(myNum) >= 100)
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Either/Or Select Options curtiss Programming and Scripting 0 01-04-2007 08:59 PM


All times are GMT -5. The time now is 02:38 PM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter