...

View Full Version : Please Help to select numbers from a list box and add it to a text box



Saurabh Tyagi
06-12-2010, 08:17 AM
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.



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/SparkServiceProvisioningSystem/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/SparkServiceProvisioningSystem/home.jsf'', line 21, character 0.

Thanks & Regards:
Saurabh

jmrker
06-12-2010, 08:54 PM
Can you simplify it to something like this ...


<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>

Saurabh Tyagi
06-13-2010, 09:04 AM
Thank You so much jmrker :thumbsup: ,
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.

Saurabh Tyagi
06-13-2010, 03:19 PM
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>

jmrker
06-13-2010, 04:14 PM
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!
:)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum