Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

jQuery / Javascript Question

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
Elxn
Asked:
Elxn
  • 2
1 Solution
 
Tom BeckCommented:
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
 
ElxnAuthor Commented:
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
 
ElxnAuthor Commented:
This should work too if you change the ID's so its close enough.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now