PDA

View Full Version : Need to change the SRC atribute of an Iframe on button click



Achyuta S
07-20-2005, 07:00 AM
Hi ALL,

I need to the SRC atribute of an Iframe on a button click.

I have displayed a pdf file in an Iframe.

<IFRAME SRC= "E:\Documents\general docs\SDKJSSnippet1.pdf" ID="testiframe"
NAME="testiframe" SCROLLING=yes WIDTH=500 HEIGHT=400 ALIGN=MIDDLE></IFRAME>

Next, I have a textbox with some text (say 'pdf') in it. Now when I click a button, the SRC attribute in the Iframe should change to "E:\Documents\general docs\SDKJSSnippet1.pdf#search='pdf'" . ie, #search='pdf' should be concatenated with the SRC attribute in the end.

Please give me the code to do this ASAP.

thanks & regards,
Achyuta

jscheuer1
07-20-2005, 11:29 AM
<script type="text/javascript">
function getTerm(){
var srchStr=document.getElementById('searchBox').value
return srchStr
}
</script>
<input type="text" id="searchBox">
<input type="button" value="Search" onmousedown="testiframe.location.replace('blank.htm');" onmouseup="testiframe.location.replace('E:\Documents\general docs\SDKJSSnippet1.pdf#search=#search=\''+getTerm()+'\'')">
<iframe name="testiframe" src="E:\Documents\general docs\SDKJSSnippet1.pdf#search="></iframe>You may have to replace the space in the pathname with %20 to get this to work. Also, adjust the iframe's properties (size, scrolling, etc.) to suit. Requires 'blank.htm':

<html>
<head>
<title></title>
</head>
<body>

</body>
</html>This last bit might not be needed. I didn't want to test on an actual .pdf file. You could try it without this by removing the onmousedown event and see what happens. Is this for local or internet use?