Solved

jQuery / Javascript Question

Posted on 2015-01-06
3
246 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
convert publisher file to an outlook email template 8 35
CSS Position not returning 2 46
WordPress Themes 10 34
how can i get a 4  at the second console.log? 6 26
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

929 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

11 Experts available now in Live!

Get 1:1 Help Now