Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am working on a html/javascript code to browse textfile and show the data in ifrmae instead of directly providing file path in src. is it possible to do so? pls provide suitale method to do that. thanks in advance
Posted
Updated 24-Nov-13 20:28pm
v2
Comments
Sergey Alexandrovich Kryukov 25-Nov-13 2:26am    
HTML is just a formatting/presentation language, it cannot "browse" or read anything. I have no idea in what way are you "working on" it. :-)
—SA
t sasi kumar 25-Nov-13 2:27am    
its not just html, javascript also included
Sergey Alexandrovich Kryukov 25-Nov-13 2:42am    
I can see your change in question, that's better. Do you mean iFrame? This is just a separate page.
And why would you want to read a file in Javascript?
—SA
t sasi kumar 25-Nov-13 2:59am    
yes, it was user requirement to have a html page in which he will give username, which should be searched in the target file and display whether availabe or not
t sasi kumar 25-Nov-13 2:59am    
I have also posted the code i tried earlier

1 solution

XML
<html>
<head>


</script>

<script>
function check1()
{

var myIFrame = document.getElementById("iframe1");

var content = myIFrame.contentWindow.document.body.innerHTML;

var names=document.getElementById("username").value ;

var n = content.search(names);

if(n==-1)
    {
        alert("not found");
    }
    else
    {
        alert("UserName Found");

        var str_array = content.split(',');

        var found=-1;

        for(var i=0; i<str_array.length; i++)
        {
            if (str_array[i]==names)
            {
                found = i;
                break;
            }
        }

        alert(str_array[found]);

        var print = str_array[found+8];
        //alert(print);
        var print_array = print.split('\n');
        alert(print_array[0]);
    }
}

</script>


</head>
<body>
<title>Get UserName Status</title>
<input type="file" name="fileread" id="fileread" />

<br></br>
<iframe  width="1000" height="1000" id='iframe1' name='iframe1' src="input.txt"> </iframe>
<br></br>
<form> Enter UserName: <input type="text" id="username" name="username"> <b></form>
<br></br>
<input type="button" onclick="check1()" value="Search" />

</body>

</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900