8 Replies - 518 Views - Last Post: 14 February 2013 - 08:41 AM

#1 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 431
  • View blog
  • Posts: 2,989
  • Joined: 12-January 10

How can i use javascript to search through multiple id's

Posted 14 February 2013 - 07:06 AM

My code:

  function CheckFileName() {
          var fileName = document.getElementById("fname_Subject_Front").value
          if (fileName == "") {
              alert("Browse to upload a valid File with jpg extension");
              return false;
          }
          else if (fileName.split(".")[1].toUpperCase() == "JPG")
              return true;
          else {
              alert("File with " + fileName.split(".")[1] + " is invalid. Upload a validfile with jpg extensions");
              return false;
          }
          return true;
      }


I have multiple id's that I have to check for the jpg extension and I am stuck on how to do this.
I tried getelementsbyname but it returns a .split error

do I have to just write a bunch of "if" statements or is there an easier way?

Is This A Good Question/Topic? 0
  • +

Replies To: How can i use javascript to search through multiple id's

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3479
  • View blog
  • Posts: 10,020
  • Joined: 08-June 10

Re: How can i use javascript to search through multiple id's

Posted 14 February 2013 - 07:13 AM

View PostDarenR, on 14 February 2013 - 03:06 PM, said:

I tried getelementsbyname but it returns a .split error

what is the error message?

despite that, getElementsByName() does not have a value property, so undefined will be returned, which is not a valid target for split().

This post has been edited by Dormilich: 14 February 2013 - 07:27 AM

Was This Post Helpful? 0
  • +
  • -

#3 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 431
  • View blog
  • Posts: 2,989
  • Joined: 12-January 10

Re: How can i use javascript to search through multiple id's

Posted 14 February 2013 - 07:20 AM

error:


Line: 4219
Error: Unable to get value of the property 'split': object is null or undefined

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3479
  • View blog
  • Posts: 10,020
  • Joined: 08-June 10

Re: How can i use javascript to search through multiple id's

Posted 14 February 2013 - 07:26 AM

yupp, as I suspected. a list of elements does not have a value property and undefined is not a string you could operate split() on.
Was This Post Helpful? 0
  • +
  • -

#5 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 431
  • View blog
  • Posts: 2,989
  • Joined: 12-January 10

Re: How can i use javascript to search through multiple id's

Posted 14 February 2013 - 07:46 AM

so then I am set to write a bunch of "if" statements then?
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3479
  • View blog
  • Posts: 10,020
  • Joined: 08-June 10

Re: How can i use javascript to search through multiple id's

Posted 14 February 2013 - 07:49 AM

why would you want to do that. just add an event handler to each field, that gives a message should the entered file name no be a JPG.
Was This Post Helpful? 0
  • +
  • -

#7 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 431
  • View blog
  • Posts: 2,989
  • Joined: 12-January 10

Re: How can i use javascript to search through multiple id's

Posted 14 February 2013 - 08:21 AM

View PostDormilich, on 14 February 2013 - 09:49 AM, said:

why would you want to do that. just add an event handler to each field, that gives a message should the entered file name no be a JPG.



the client specified that they only want jpg files to be able to upload. Simply telling them not to do it is not good enough for the client.
Was This Post Helpful? 0
  • +
  • -

#8 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3479
  • View blog
  • Posts: 10,020
  • Joined: 08-June 10

Re: How can i use javascript to search through multiple id's

Posted 14 February 2013 - 08:25 AM

you need a server-side solution anyways since JS disabled users will complain that the upload doesn’t work.

nevertheless, if politeness doesn’t help check each input separately. which (IMO) translates into a loop, rather than multiple if()s.
Was This Post Helpful? 0
  • +
  • -

#9 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 431
  • View blog
  • Posts: 2,989
  • Joined: 12-January 10

Re: How can i use javascript to search through multiple id's

Posted 14 February 2013 - 08:41 AM

View PostDormilich, on 14 February 2013 - 10:25 AM, said:

you need a server-side solution anyways since JS disabled users will complain that the upload doesn’t work.

nevertheless, if politeness doesn’t help check each input separately. which (IMO) translates into a loop, rather than multiple if()s.



this perticular client is a pain in the ass to say the least-- basically they are trying to automate as much as they can so they can lay off a ton of their workers. We are currently trying not to help them as much as possible to prevent this since our owner owns some of that company(small stake) and does not agree with the majority ownership for that company.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1