Java Scripts Alert Box

I did this Java Script function and is hoping when Price1's value is 0 ~3  or 7~8,  and Text Area for Price1 Note is empty, the page will prompt an alert box telling the users that they must write down reasons for the given price.

normally, users will first fill in Price field, then Note field.  this function beheaves alright in this case.

however, if the users opt to fill in the Note field before filling in the Price field.  The page is still prompting the users alert box"Please tell me reasons for the Price!"

Any idea of what's wrong with the java scripts below?

Thank you!
function Price1()
{
  if ( 
        document.form.Price1.value == 0 || document.form.Price1.value == 1 ||
        document.form.Price1.value == 2 || document.form.Price1.value == 3 ||
        document.form.Price1.value == 7  || document.form.Price1.value == 8 ||
        document.form.Price1.value == 9 || document.form.Price1.value == 10
					   
      && 
					   
	document.form.txtarea_Note.value==''
					 

      )
					   
     { alert('Please tell me reasons for the Price!')
     }
		
}

Open in new window

cuconsortiumAsked:
Who is Participating?
 
jkofteCommented:
you should get your or into pharanthesis.

function Price1()
{
  if (
       (document.form.Price1.value == 0 || document.form.Price1.value == 1 ||
        document.form.Price1.value == 2 || document.form.Price1.value == 3 ||
        document.form.Price1.value == 7  || document.form.Price1.value == 8 ||
        document.form.Price1.value == 9 || document.form.Price1.value == 10)
                                
      && 
                                
      document.form.txtarea_Note.value==''
                              

      )
                                
     { alert('Please tell me reasons for the Price!')
     }
            
}
0
 
Pratima PharandeCommented:
Th Javascript function must be called on Notes textbox thats why its asking ther
there is no problem in javascript
call the javascript on buttonclick or something else
0
 
cuconsortiumAuthor Commented:
I just added paranthesis arround my OR , the alert box doesn't want to prompt at all.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Pratima PharandeCommented:
can you share html code where function get called ?
0
 
cuconsortiumAuthor Commented:
The java script is called on Price1 (a drop down box, OnClick ).

There'll be Price2, Price3, Price4 fields, so it's impossible to put a button to for each Price to trigger the Alert Box.
0
 
cuconsortiumAuthor Commented:
yes, I'll pot it shortly.
0
 
cuconsortiumAuthor Commented:
<fieldset onclick="Price1()">
                            <label for="Price1"><span class="style33">Rating:</span></label>
                            <select name="Price1" id="Price1" >
                              <option value="0" selected="selected">0</option>
                              <option value="1">1</option>
                              <option value="2">2</option>
                              <option value="3" >3</option>
                              <option value="4">4</option>
                              <option value="5">5</option>
                              <option value="6">6</option>
                              <option value="7">7</option>
                              <option value="8">8</option>
                              <option value="9">9</option>
                              <option value="10">10</option>
                            </select>
                          </fieldset>
0
 
Pratima PharandeCommented:
txtarea_Note is inside fieldset ??
is yes take it outside it will work
0
 
cuconsortiumAuthor Commented:
no, txtarea_Note is Outside of fieldset.
0
 
cuconsortiumAuthor Commented:
<textarea name="txtarea_Note" cols="33" rows="5" id="txtarea_Note"></textarea>
0
 
Pratima PharandeCommented:

try this

<fieldset >
                            <label for="Price1"><span class="style33">Rating:</span></label>
                            <select name="Price1" id="Price1" onchange="Price1()">
                              <option value="0" selected="selected">0</option>
                              <option value="1">1</option>
                              <option value="2">2</option>
                              <option value="3" >3</option>
                              <option value="4">4</option>
                              <option value="5">5</option>
                              <option value="6">6</option>
                              <option value="7">7</option>
                              <option value="8">8</option>
                              <option value="9">9</option>
                              <option value="10">10</option>
                            </select>
                          </fieldset>
0
 
cuconsortiumAuthor Commented:
<fieldset> doesn't have OnChange event.  but, I tried it anyway.  it doesn't prompt Alert Box.  I also try OnKeyUp. Still doesn't prompt Alert Box.

This <fieldset> is associated with a jQuery Slider.  This Slider consists of a Drop Down Box and a Slider.  The option value defines the value on the drop down box and the scale on the slider.

Here is the jQuery Slider  URL:  http://filamentgroup.com/lab/update_jquery_ui_slider_from_a_select_element_now_with_aria_support/
Download jQuery Slider Code: http://filamentgroup.com/examples/slider_v2/FilamentGroup_selectToUISlider.zip
0
 
Pratima PharandeCommented:
add onchange on

<select name="Price1" id="Price1" onchange="Price1()">
0
 
cuconsortiumAuthor Commented:
oh, didn't see it's on "select".
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.