Solved

Java Scripts Alert Box

Posted on 2011-03-04
14
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
14 Comments
 
LVL 9

Accepted Solution

by:
jkofte earned 250 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 250 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AJAx/JQuery/JSON Error 3 38
Scroll 5 news at a time using vticker 2 39
Sticking text to shapes in Raphael.js 6 40
Angular - difference between these 2 codes 3 15
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

734 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