Solved

Java Scripts Alert Box

Posted on 2011-03-04
14
231 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 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now