Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: Easy Question

  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Easy Question

    Hello Experts, I have a question for you. Keep in mind that I am a noob. Please dont bash me. Thank you in advance for your help.

    I am looking for a javascript code that will take data inserted into a text box (form?) and put it into a drop down box.

    For example, a user comes to my website and in a text box enters:

    1
    2
    3
    4
    5

    and the user clicks "OK"

    I want the javascript to take the 1 2 3 4 5 and put it into a drop down box. The drop down box is right besides the text box. Then once the data is properly in the drop down box the user can "SUBMIT" (VIA POST) this information to me.

    Thanks for your help, I will not mind paying for this if necessary.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    function setSelect(what)
    {
    	document.forms[0].drop.options.length = 0;
    	var num = /\d/;
    	var theOption1 = document.forms[0].drop.options[0]=new Option('How many?','null', true, false);
    	var j = 1;
    	if(num.test(what))
    	{
    		for(i = 0; i <= parseInt(what); i++)
    		{
    			var theOptions = document.forms[0].drop.options[j++]=new Option(i,i, false, false);
    		}
    	}
    }
    </script>
    </head>
    
    <body>
    <form action="#" method="post">
    <input type="text" name="howmany" onKeyUp="setSelect(this.value)">
    <select name="drop">
    <option value="null">How many?</option>
    </select>
    </form>
    </body>
    </html>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    But... what is the use?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    New Coder
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Aerospace thank you so much for that. It's almost what I needed.

    In your code the drop down is fed by an input box that can only accept one number. I actually need like a textarea where a user can enter multiple numbers (line by line) like:

    2
    4
    7
    10

    and then they get "moved" into the drop down box as follows:

    <option value="2">2</option>
    <option value="4">4</option>
    <option value="7">7</option>
    <option value="10">10</option>

    Kor,

    I need this because I have a form that must be submitted using the select element. To feed the data for submission I need the user to type in some numbers.

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Still I don't see the point... From the CGI/server side point of view, it does not matter which kind of the controls (input, select...) sends data. As long as you have already a control (input, textarea...) why to double the data sent?.... Server side application will receive both your text control data and your select control data as well.
    Last edited by Kor; 10-13-2006 at 03:35 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    New Coder
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, but I don't have control of the server side.

    Server side is set to accept data from <select> element only. That is why I must feed data into <select> by hook or by crook.

  • #7
    New Coder
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I need this code and will pay for it. Please PM me if needed.

  • #8
    New Coder
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This function "moves" but I don't know how to change it to make it work for me.

    Code:
    	
           function move(fbox,tbox) {
    		var arrFbox = new Array();
    		var arrTbox = new Array();
    		var arrLookup = new Array();
    		var i;
    		
    		for(i = 0; i < tbox.options.length; i++){
    			arrLookup[tbox.options[i].value] = tbox.options[i].text;
    			arrTbox[i] = tbox.options[i].value;
    		}
    		
    		var fLength = 0;
    		var tLength = arrTbox.length;
    		
    		for(i = 0; i < fbox.options.length; i++) {
    			arrLookup[fbox.options[i].value] = fbox.options[i].text;
    		
    			if(fbox.options[i].selected && fbox.options[i].value != ""){
    				arrTbox[tLength] = fbox.options[i].value;
    				tLength++;
    			}else{
    				arrFbox[fLength] = fbox.options[i].value;
    				fLength++;
    			}
    		}
    		
    		fbox.length = 0;
    		tbox.length = 0;
    		var c;
    		
    		for(c = 0; c < arrFbox.length; c++) {
    			var no = new Option();
    			no.text = arrLookup[arrFbox[c]];
    			no.value = arrFbox[c];
    			fbox[c] = no;
    		}
    		
    		for(c = 0; c < arrTbox.length; c++) {
    			var no = new Option();
    			no.text = arrLookup[arrTbox[c]];
    			no.value = arrTbox[c];
    			tbox[c] = no;
    		}
    	}

  • #9
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Okay now I think you should explain what it is that you are really trying to do as it seems to you are trying to get around something since you have no control of the server side stuff.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #10
    New Coder
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Im trying to submit values to a server. Users will come to my site and type in some numbers in a textarea like....

    52151
    91818
    13518
    46618
    39184

    I need those numbers converted into an option value in a select drop down box.

    The server is not owned or operated by me. The server is configured to only process drop down value numbers. This is for a weather application. Users are entering zip codes to see weather in their surrounding area. No harm being done here.
    Last edited by holyearth; 10-13-2006 at 04:31 PM.

  • #11
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    function setSelect()
    {	
    	document.forms[0].drop.options.length = 0;
    	var thenums;
    	if(!window.attachEvent)
    	{
    		thenums = document.forms[0].howmany.value.split('\n');
    	}
    	else
    	{
    		thenums = document.forms[0].howmany.value.split('\r\n');
    	}
    	var num = /^([0-9]+)$/;
    	for(var i = 0; i < thenums.length; i++)
    	{
    		if(num.test(thenums[i]))
    		{
    			var theOptions = document.forms[0].drop.options[i]=new Option(thenums[i],thenums[i], false, false);
    		}
    	}
    }
    </script>
    </head>
    <body>
    <form action="#" method="post">
    	<textarea name="howmany" cols="20" rows="10" onblur="setSelect()"></textarea>
    	<select name="drop">
    	</select>
    </form>
    </body>
    </html>
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #12
    New Coder
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Aerospace,

    Thanks that was it.

    Aerospace, can you PM me with an email address perhaps? I would really like to paypal you some funds for helping me out. I appreciate your time. If you want, please email me at holyearth [at] gmail.com

    Regards

  • #13
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Ok, here's your code:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="txt/javascript">
    <script type="text/javascript">
    function build(f){
    var t=f['tx'], s=f['sel'], i=0, v
    var val=t.value.split(document.all?'\r\n':'\n');
    while(v=val[i++]){
    var o=document.createElement('option')
    o.setAttribute('value',v);
    o.appendChild(document.createTextNode(v))
    s.appendChild(o)
    }
    }
    </script>
    </head>
    <body>
    <form>
    <textarea name="tx"></textarea>
    <select name="sel">
    </select>
    <br>
    <br>
    <input type="button" value="Complete" onclick="build(this.form)">
    </form>
    </body>
    </html>
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #14
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Why are you both using object detection for the split() delimiter? Kor, you shouldn't ever use document.all to detect IE.

    IE4+ and NS4+ support using RegExp in addition to strings. (That was standardized in ECMA-Script 3.)

    Code:
    split(/[\r\n]+/)
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

  • #15
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by Kravvitz View Post
    Why are you both using object detection for the split() delimiter? Kor, you shouldn't ever use document.all to detect IE.

    IE4+ and NS4+ support using RegExp in addition to strings. (That was standardized in ECMA-Script 3.)

    Code:
    split(/[\r\n]+/)
    ..because, for unknown reasons, IE and Moz react different to the split upon \r\n
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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