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.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please Help to select numbers from a list box and add it to a text box

    hi please help,
    i want to select numbers from a list box and add it to a text box with comma separated. my java script code does not work into browser but work fine into eclipse jsp view.

    Code:
    		function passingNumbersToTextArea(numToCall,allNum)
    		{
    			var numFromList=document.getElementById(allNum);
    			var numToTextArea=document.getElementById(numToCall);
    			if(numToTextArea.value.search(numFromList.value)!=-1)//if duplicate Number is exist
    			{
    				alert("Duplicate Number Can not be added :");
    				return false;
    			}
    			else 
    			{
    				if(numToTextArea.value.length!=0)
    				{
    				// If textarea has value than it added another value with comma seperated 
    					numToTextArea.value=numToTextArea.value+','+numFromList.value;
    					return false;
    				}	
    				else
    				{				 
    					numToTextArea.value=numFromList.value;
    					return false;
    				}
    			}	
     		}
    
    
    jsp code 
    
    <h:inputTextarea cols="10" rows="4" id="numberToCall" required="true"
    value="#{conferenceCall.numberToCall}" styleClass="form_input_box" />
    <h:selectOneListbox styleClass="form_selectmenu" id="allNumbers" size="5" onclick="passingNumbersToTextArea('numberToCall','allNumbers');">
    <f:selectItem itemValue="9971701077" itemLabel="Sharad : 9971701077"/>
    <f:selectItem itemValue="9990102381" itemLabel="Saurabh : 9990102381"/>							
    </h:selectOneListbox>
    javascript debugger shows error

    Error ``numToTextArea is null'' [x-] in file ``http://localhost:8888/SparkServicePr...ystem/home.jsf'', line 21, character 0.
    Exception ``TypeError: numToTextArea is null'' thrown from function passingNumbersToTextArea(allNum=string:"allNumbers", numToCall=string:"numberToCall") in <http://localhost:8888/SparkServiceProvisioningSystem/home.jsf> line 21.
    [e] message = [string] "numToTextArea is null"
    Exception ``TypeError: numToTextArea is null'' thrown from function onclick(event=MouseEvent:{0}) in <http://localhost:8888/SparkServiceProvisioningSystem/home.jsf> line 1.
    [e] message = [string] "numToTextArea is null"
    Error ``TypeError: numToTextArea is null'' [x-] in file ``http://localhost:8888/SparkServicePr...ystem/home.jsf'', line 21, character 0.

    Thanks & Regards:
    Saurabh

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts

    Lightbulb Something like this ...

    Can you simplify it to something like this ...
    Code:
    <html>
    <head>
    <title>List to Text Box</title>
    <script type="text/javascript">
    http://www.codingforums.com/showthread.php?t=197984
    
    var picks = [];
    function collect(info) {
      var sel = document.getElementById('TArea');
      if (info == '') { sel.value = ''; picks = []; return; }
      picks.push(info);
      sel.value = picks.join(', ');
    }
    
    </script>
    </head>
    <body>
    <select id="LBox" onchange="collect(this.value)">
     <option value="">Choose value</option>
     <option value="10">10</option>
     <option value="9">9</option>
     <option value="8">8</option>
     <option value="7">7</option>
     <option value="6">6</option>
     <option value="5">5</option>
     <option value="4">4</option>
     <option value="3">3</option>
     <option value="2">2</option>
     <option value="1">1</option>
     <option value="">Clear</option>
    </select>
    <p>
    <textarea id="TArea"></textarea>
    </body>
    </html>

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank You so much jmrker ,
    actually i am a beginner, so i have no idea to write code like that, your code is simple and powerful, it make me so much help.

    But still it is not working on Mozilla IE or any browser.

    my problem is that it is working on my eclipse jsp view, but not working with browsers when i deployed my app. to tomcat.

  • #4
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Solve the problem

    OK I got this problem, it was with by JSF tag

    it should called like that

    function passingNumbersToTextArea(Lbox,form)
    {
    try{
    //var tArea=document.forms['ConferenceForm'].elements['ConferenceForm:TArea'];
    // var tArea=document.getElementById("ConferenceForm:TArea");
    var tArea=form["ConferenceForm:TArea"];
    if(tArea.value.search(Lbox)!=-1)//if duplicate Number is exist
    {
    alert("Duplicate Number Can not be added :");
    return false;
    }
    else
    {
    if(tArea.value.length!=0)
    {
    // If textarea has value than it added another value with comma seperated
    tArea.value=tArea.value+','+Lbox;
    return false;
    }
    else
    {
    tArea.value=Lbox;
    return false;
    }
    }
    }catch(e) {alert(e);}
    }



    and JSF CODE like

    <h:inputTextarea cols="30" rows="4" id="TArea" required="true"
    value="#{conferenceCall.numberToCall}" styleClass="form_input_box" />


    <h:selectOneListbox styleClass="form_selectmenu" id="LBox" size="5" onclick="passingNumbersToTextArea(this.value, this.form)">
    <f:selectItems value="#{userNumbers.options}"/>
    </h:selectOneListbox>

  • #5
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,026
    Thanks
    36
    Thanked 494 Times in 488 Posts

    Thumbs up

    Quote Originally Posted by Saurabh Tyagi View Post
    OK I got this problem, it was with by JSF tag

    it should called like that
    ...
    I'm glad you got it figured out ... I have no idea what JSF or tomcat is!

    I would have never thought to make suggestions there as I don't use either
    and I did not notice either being mentioned in the previous posts.


    Anyway, I'm glad I could help.
    Good Luck!


  •  

    Posting Permissions

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