...

View Full Version : I'm a newbie...be gentle help needed urgent html jscript



rex123
08-31-2011, 09:59 AM
hi i am trying to populate a textarea with the selections
like
checkboxes
radiobuttons
textbox
combobox

but i cant seem to do so. i am naive to the field of programing, and found a few code snippets to do so i tried but it did no good... help needed

this is my code
"

<html>
<head>
<style type="text/css">

.minitext { font: normal 0.7em Arial, sans-serif; color: Black; }

.disable {
background-color: #CF110C;
color: #fff;
font-weight: bold;
padding: 5px;
}

</style>



<script language="Javascript" type="text/javascript">

function populateTextArea(){

var output = new Array();
var fieldID = 1;


while (fieldObj = document.MyForm['iid'+fieldID]) {

if (fieldObj.length)
{ for (var j=0; j<fieldObj.length; j++)
{
if (fieldObj[j].checked) { output[output.length] = fieldObj[j].value;}
}//end of for
} //end of if
else
{
if (fieldObj.checked) { output[output.length] = fieldObj.value; }
}//end of else

fieldID++;
}// end of while

document.getElementById('targetarea').value = output.join(', ');
//document.MyForm.targetarea.value = document.MyForm.ip1.value + '\n' + document.MyForm.ip2.value + '\n' + document.MyForm.ip3.value ;
}

</script>
</head>

<body>
<br>
<br>

<form name="MyForm" method="POST" action="#">

String 1: <input type="text" name="ip1" value=""><br>
String 2: <input type="text" name="ip2" value=""><br>
String 3: <input type="text" name="ip3" value=""><br><br>


<input type="checkbox" name="iid1" id="pe_item2" value="Text string 1"> Text string
<input type="checkbox" name="iid1" id="pe_item2" value="Text string 12"> Text string 1<br><br><br>

<input type="radio" name="iid2" id="pe_item4" value="Text string 2">Text string 2
<input type="radio" name="iid2" id="pe_item6" value="Text string 3">Text string 3<br>
<input type="radio" name="iid3" id="pe_item8" value="Text string 4">Text string 4
<input type="radio" name="iid3" id="pe_item10" value="Text string 5">Text string 5<br>
<input type="radio" name="iid4" id="pe_item12" value="Text string 6">Text string 6
<input type="radio" name="iid4" id="pe_item14" value="Text string 7">Text string 7<br>


<br>



<br>
<a href="#" onClick="document.MyForm.targetarea.value = document.MyForm.ip1.value + '\n' + document.MyForm.ip2.value + '\n' + document.MyForm.ip3.value + populateTextArea();" >Populate</a><br><br>
<INPUT TYPE=BUTTON VALUE="Co" ONCLICK= populateTextArea(); >
<br>

<textarea id="targetarea" name ="targetarea" cols="50" rows="5"></textarea>
</form>



</body>
</html>


"

help need this done urgently

Philip M
08-31-2011, 12:35 PM
I find your element names rather confusing.


<form name="MyForm" method="POST" action="#">

String 1: <input type="text" name="ip1" value=""><br>
String 2: <input type="text" name="ip2" value=""><br>
String 3: <input type="text" name="ip3" value=""><br><br>


<input type="checkbox" name="cbox1" id="pe_item1" value="Text string 1"> Text string
<input type="checkbox" name="cbox2" id="pe_item2" value="Text string 12"> Text string 1<br><br><br>

<input type="radio" name="iid2" id="pe_item4" value="Text string 2">Text string 2
<input type="radio" name="iid2" id="pe_item6" value="Text string 3">Text string 3<br>

<input type="radio" name="iid3" id="pe_item8" value="Text string 4">Text string 4
<input type="radio" name="iid3" id="pe_item10" value="Text string 5">Text string 5<br>

<input type="radio" name="iid4" id="pe_item12" value="Text string 6">Text string 6
<input type="radio" name="iid4" id="pe_item14" value="Text string 7">Text string 7<br>


<br>



<br>

<INPUT TYPE=BUTTON VALUE="Populate Text Area" ONCLICK= populateTextArea(); >
<br>

<textarea id="targetarea" name ="targetarea" cols="50" rows="5"></textarea>
</form>

<script type = "text/javascript">
function populateTextArea(){
var f = document.MyForm;
var a1 = f.ip1.value;
var a2 = f.ip2.value;
var a3 = f.ip3.value;
if (f.cbox1.checked) {var c1 = f.cbox1.value}
if (f.cbox2.checked) {var c2 = f.cbox2.value}
if (f.iid2[0].checked) {var r1 = f.iid2[0].value}
if (f.iid2[1].checked) {var r1 = f.iid2[1].value}
if (f.iid3[0].checked) {var r2 = f.iid3[0].value}
if (f.iid3[1].checked) {var r2 = f.iid3[1].value}
if (f.iid4[0].checked) {var r3 = f.iid4[0].value}
if (f.iid4[1].checked) {var r3 = f.iid4[1].value}

var message = "";
if (a1) {message += a1 + "\n"}
if (a2) {message += a2 + "\n"}
if (a3) {message += a3 + "\n"}
if (c1) {message += c1 + "\n"}
if (c2) {message += c2 + "\n"}
if (r1) {message += r1 + "\n"}
if (r2) {message += r2 + "\n"}
if (r3) {message += r3 + "\n"}

f.targetarea.value = message;
}

</script>


Quizmaster: Which musical, written in 1953 by Robert Wright and George Forrest, was set in medieval Baghdad?
Contestant: South Pacific.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum