SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2002
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Option/Select Box Validation?

    Is it possible to check an option/select box to see if it still has data in it?

    I'd like to be able to stop a user from updating a file IF the field they are copying from still has content in it.

    I.e.

    BOX 1 BOX 2
    1 3
    4
    6
    2
    5

    So the button will display an error message (e.g. you aint sent the entire lot over)

    I've tried to attempt it but my mind cannot really handle anything more than (Check kettle for water, IF water equal or less than 1 cup full, then fill kettle with water, If kettle equal to or greater than 3 then STOP)

    Cheers Dom

  2. #2
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, it's pretty easy to do. I can't get any code to you yet, since I just got swamped at work, but on my lunch break I'll come back hopefully, with some code that'll do the trick. If this is urgent, then I would post in the DHTML/Javascript forum and they can get you an answer before my lunch break

    Drew
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.

  3. #3
    SitePoint Member
    Join Date
    May 2002
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks Drew

    I'll look forward to it..

    Hopefully i'll be able to understand it

    thanks for the reply

  4. #4
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im sorry about the wait. Here is the code I came up with. I hope it does what you want. Let me know if I didn't interpret you correctly.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    	<title>Untitled</title>
    
    <script language= "Javascript">
    function checkSelect () {
      if (document.form1.submitOK.value == "false") {
      	 alert ("You still have a value selected")
    	 return false;
    	 document.form1.select.focus()
      }
    }
    function selected(x) {
      document.form1.select.options[x].selected = true;
      if (x != 0) {
      	 document.form1.submitOK.value = false;
      }
      else { 
      	 document.form1.submitOK.value = true;
      }
    }
    </script>
    </head>
    
    <body>
    <form name="form1" method="post" onSubmit="checkSelect();">
    <select name="select" onChange="selected(this.options[this.selectedIndex].value);">
    	<option value="0">None</option>
    	<option value="1">Red</option>
    	<option value="2">Blue</option>
    	<option value="3">Yellow</option>
    </select>
    <input type="hidden" name="submitOK">
    <input type="submit" value="submit">
    </form>
    
    </body>
    </html>
    Drew
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •