...

View Full Version : How do I use sub/string to populate?



ferrariboy21
12-27-2008, 09:35 AM
When I browse a 'txt' file and click on upload, it appears in an iFrame below. How do I extract that values below and populate it in the blank spaces above?
eg. (Apple instead of Q1; 31 instead of Fill in Value)

I was told to use something like strings. Can someone please elaborate more?

Image: http://img261.imageshack.us/img261/9841/populatelb9.jpg
http://img261.imageshack.us/img261/9841/populatelb9.jpg

Philip M
12-27-2008, 11:28 AM
You will need to post your mark-up and Javascript code.

You have six fruits and only five input boxes - clarify, please.

ferrariboy21
12-27-2008, 11:57 AM
This is the code.



<script language="JavaScript" type="text/javascript">
<!--
function uploadfile () {
loadOuter ( document.getElementById ( "browsefile" ).value );
}
var srcFrame;
//External content into a layer
function loadOuter(doc) {
srcFrame = document.getElementById("hiddenContent");
srcFrame.src = doc;
// workaround for missing onLoad event in IFRAME for NN6
if (!srcFrame.onload) {
setTimeout("transferHTML()", 1000)
}
}

function transferHTML(){
srcContent='';
if (srcFrame.contentDocument){
srcContent=srcFrame.contentDocument.getElementsByTagName("BODY")[0].innerHTML;
}
else if (srcFrame.contentWindow){
srcContent=srcFrame.contentWindow.document.body.innerHTML;
}
document.getElementById("outerDisplay").innerHTML = srcContent
}


var DocAry=new Array('Test.txt','Test2.txt');

function SelectList(v){
if (v>0){
loadOuter(DocAry[v-1]);
}
}

//-->
</script>




<script type="text/javascript">
function ShowInputs()
{
var idx=document.getElementById ( "menu1" ).selectedIndex-1;
var valuearray = new Array ();
var xaxisarray = new Array ();
var inputarray = new Array ();
var colorarray = new Array ();
var color2array = new Array ();
for (i=0;i<=idx;i++) {
var xaxisid = "axis"+i;
if ( document.getElementById ( xaxisid ) != null ) {
if ( document.getElementById ( xaxisid ).value != "" ) {
xaxisarray[i] = '<input type="text" id="axis'+i+'" size="3" value="'+document.getElementById ( xaxisid ).value+'" />';
}
}
else {
xaxisarray[i] = '<input type="text" id="axis'+i+'" size="3" value="Q'+i+'" />';
}
var colorid = "input_field_"+i;
if ( document.getElementById ( colorid ) != null ) {
if ( document.getElementById ( colorid ).value != "" ) {
colorarray[i] = '<input type="hidden" id="input_field_'+i+'" size="9" value="'+document.getElementById ( colorid ).value+'">';
color2array[i] = '<input type="text" disabled="true" id="sample_'+i+'" size="1" value="" style="background-color:'+document.getElementById ( colorid ).value+'" />';
}
}
else {
colorarray[i] = '<input type="hidden" id="input_field_'+i+'" size="9" value="#FFFFFF">';
color2array[i] = '<input type="text" disabled="true" id="sample_'+i+'" size="1" value="" style="background-color:#FFFFFF" />';
}
var inputid = "input"+i;
if ( document.getElementById ( inputid ) != null ) {
if ( document.getElementById ( inputid ).value != "" ) {
inputarray[i] = '<input type="text" name="entry" onkeyup="valid(this)" id="input'+i+'" value="'+document.getElementById ( inputid ).value+'"/>';
}
}
else {
if ( i == 0 || i == 1 || i == 2 )
inputarray[i] = '<input type="text" name="entry" onkeyup="valid(this)" id="input'+i+'" value="50"/>';
else
inputarray[i] = '<input type="text" name="entry" onkeyup="valid(this)" id="input'+i+'" value="Fill in value"/>';
}
}
// reset container content before adding inputs
document.getElementById('container').innerHTML = '';

for (i=0;i<=idx;i++) {
document.getElementById('container').innerHTML += '<b>X-Axis</b>:<br>'+xaxisarray[i]+'&nbsp;&nbsp;&nbsp;&nbsp;';
document.getElementById('container').innerHTML += '<input type="button" onclick="showColorGrid2(\'input_field_'+i+'\',\'sample_'+i+'\');" value="Color">';
document.getElementById('container').innerHTML += '&nbsp;'+colorarray[i];
document.getElementById('container').innerHTML += '&nbsp;'+color2array[i];
document.getElementById('container').innerHTML += '&nbsp;'+inputarray[i]+'<br>';
document.getElementById('container').innerHTML += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div id="colorpicker201" class="colorpicker201"></div>';
}
}

</script>



You have six fruits and only five input boxes - clarify, please.

That was just an example mate. So let say it's 6 fruits and 6 input boxes.

Cheers for the reply. :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum