[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

jQuery / Javascript Question

Posted on 2015-01-06
3
Medium Priority
?
256 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
[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
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
Tom Beck earned 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
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…
Suggested Courses

656 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