Advanced Search

Results 1 to 4 of 4

Thread: Affect new value to combox which is not in options

  1. #1
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default Affect new value to combox which is not in options

    Hello

    I wonder if there is a way to affect a value to a combobox which does not exists in predefined options ?

    html part
    Code:
    <select name="EmailList" id="EmailListID">
    		<option value=""></option>
    		<option value="a@b.com">a@b.com</option>
    		<option value="c@d.com">c@d.com</option>
    </select>
    <textarea style="resize:none;overflow:hidden;display:none;" rows="1" cols="32" maxlength="128" name ="otherEmail" id="otherEmailID" value=""></textarea>
    <input type="checkbox" name="EmailCheckBox" id="EmailCheckBoxID" onChange="checkEmailCheckBox();">
    javascript part
    Code:
    function checkEmailCheckBox(){
    
    var EmailListValue = document.getElementById('EmailListID').value;
    var OtherEmailValue = document.getElementById('EmailListID').value;
    
    	if (document.getElementById('EmailCheckBoxID').checked){
    		document.getElementById('otherEmailID').value = EmailListValue;  // <---- always works
                    document.getElementById('EmailListID').style.display = 'none';
    		document.getElementById('otherEmailID').style.display = 'block';
    	} else {
    		document.getElementById('EmailListID').value = OtherEmailValue;  // <---- works only if the set value is present in combobox options ( here : a@b.com or c@d.com ) 
    										//	if try to force another value it becomes 'empty value'...
    		document.getElementById('EmailListID').style.display = 'block';
    		document.getElementById('otherEmailID').style.display = 'none';
    	}
    }
    Thanks
    Last edited by sfchun; 02-20-2013 at 10:50 AM.

  2. #2
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    it seems I found a new thing we cannot do with javascript

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,705
    Thanks
    43
    Thanked 3,133 Times in 3,097 Posts
    Blog Entries
    12

    Default

    If you want to set a select's value to something none of its options have, you need to create a new option element with that value and append it to the select element first.

    Demo:

    http://home.comcast.net/~jscheuer1/s...ns-email-h.htm
    Last edited by jscheuer1; 03-06-2013 at 03:06 PM. Reason: add demo
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. The Following User Says Thank You to jscheuer1 For This Useful Post:

    sfchun (03-07-2013)

  5. #4
    Join Date
    Apr 2008
    Posts
    58
    Thanks
    22
    Thanked 0 Times in 0 Posts

    Default

    Thanks a lot for your reply !

Similar Threads

  1. Boxover affect problem
    By biomike in forum CSS
    Replies: 2
    Last Post: 12-29-2009, 08:49 PM
  2. Resolved Why does this character affect a query?
    By DeSaaD37 in forum MySQL and other databases
    Replies: 4
    Last Post: 03-18-2009, 11:25 PM
  3. Making Combox Viewer Script Dynamic
    By So_Cute in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 08-13-2007, 04:23 AM
  4. Fade affect for slideshow
    By ak7861 in forum JavaScript
    Replies: 3
    Last Post: 10-14-2006, 05:33 AM
  5. about the carusel image affect
    By odelya in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 03-09-2005, 10:13 PM

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
  •