[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Java Scripts Alert Box

Posted on 2011-03-04
14
Medium Priority
?
238 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:cuconsortium
  • 8
  • 5
14 Comments
 
LVL 9

Accepted Solution

by:
jkofte earned 1000 total points
ID: 35034385
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
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35034390
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
 

Author Comment

by:cuconsortium
ID: 35034410
I just added paranthesis arround my OR , the alert box doesn't want to prompt at all.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35034421
can you share html code where function get called ?
0
 

Author Comment

by:cuconsortium
ID: 35034438
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
 

Author Comment

by:cuconsortium
ID: 35034440
yes, I'll pot it shortly.
0
 

Author Comment

by:cuconsortium
ID: 35034454
<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
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35034462
txtarea_Note is inside fieldset ??
is yes take it outside it will work
0
 

Author Comment

by:cuconsortium
ID: 35034474
no, txtarea_Note is Outside of fieldset.
0
 

Author Comment

by:cuconsortium
ID: 35034482
<textarea name="txtarea_Note" cols="33" rows="5" id="txtarea_Note"></textarea>
0
 
LVL 39

Assisted Solution

by:Pratima Pharande
Pratima Pharande earned 1000 total points
ID: 35034495

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
 

Author Comment

by:cuconsortium
ID: 35034725
<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
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35034750
add onchange on

<select name="Price1" id="Price1" onchange="Price1()">
0
 

Author Comment

by:cuconsortium
ID: 35088598
oh, didn't see it's on "select".
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question