Solved

jQuery / Javascript Question

Posted on 2015-01-06
3
244 Views
Last Modified: 2015-01-06
I have a simple jquery script that works on one page, but when I use it on another page it doesn't work.

I have a simple script that checks if a file input is empty, and if it is not empty it checks if a select box has a value.  If the file is there but the user hasn't picked the image type it should return false and display a little error message.  But it doesn't work!

See the problem Click Here  then click the profile picture link that says update your picture (it will appear when you hover over it).

if($("#upload_pic").val() != ''){
					  	alert("in");
						  if($("#pic_type").val() == 0){
							$("#pic_type_alert").show(); 
						  }
						  return false;
					  }

Open in new window


The HTML:
<form id="update_status">
				<input type="file" id="upload_pic" name="initial_profile" />
				
				<select id="pic_type" name="pic_type" style="margin-top:4px;">
						<option selected="selected" value="0">Choose a Pic Type&#8230;</option>
						<option value="1">option</option>
				</select> <span class="hide" id="pic_type_alert" style="color:#FF0000; font-size:11px; font-weight:bold;">* Choose Type!</span>
				<textarea placeholder="Add a Description to your Picture..." name="description"></textarea>
				</form>

Open in new window


Also you can use Chrome to see the code that ajaxed in to the page and get a better idea of whats going on.

Thanks!
0
Comment
Question by:Elxn
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
ID: 40534557
Here's a suggestion. Alert out the current value of the select when the button is clicked. You are testing to see if it's zero but maybe the type is wrong. You have zero as an integer, maybe it's looking for a string.

function upload_form(){
                                //make sure pic_type is selected
                                if($("#profile_pic").val() != ''){
                                      alert("in: " + $("#pic_type").val());
                                      if($("#pic_type").val() === "0"){
                                          $("#pic_type_alert").show();
                                            return false;
                                      }                                      
                                }
0
 
LVL 2

Author Comment

by:Elxn
ID: 40534694
My dumb ass just figured it out.  I had another form with the same ID's in it.  I just changed the ID's on the code and it worked fine.

Sorry EE, don't know why i just thought of the answer!
0
 
LVL 2

Author Closing Comment

by:Elxn
ID: 40534697
This should work too if you change the ID's so its close enough.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
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)

706 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

16 Experts available now in Live!

Get 1:1 Help Now