Results 1 to 14 of 14

Thread: [RESOLVED] Set Text in textbox within an iframe

  1. #1
    Lively Member SavedByGrace's Avatar
    Join Date
    May 06
    Posts
    114

    Resolved [RESOLVED] Set Text in textbox within an iframe

    I have been struggling with this for quite some time and just cannot work this out. I am trying to set text within a textbox that is within an iframe which has no name. I tried several different methods to access the textbox element called "element_2_1" but I haven't had any luck. I am able to identify the frame using GetElementsByTagName and looking for the title of the frame (see code below) but that is as far as I have been able to go. I would greatly appreciate any help I can get on this.

    Snippet of iframe Source:
    <p><iframe height="2981" allowTransparency="true" frameborder="0" scrolling="no"
    style="width:90%;border:none" src="http://someurl.com/someform/embed.php?id=2"
    title="This is some page title - example page title!"><a
    href="http://someurl.com/someform/view.php?id=2" title="This is some page title - example page title!" onclick="pageTracker._trackPageview('/outgoing/someurl.com/someform/view.php?id=2&amp;referer=http%3A%2F%some.referer.com%2Fhub%2Fs');">This is some page title - example page title!</a></iframe></p>
    iframe's Textbox Source:
    <input id="element_2_1" name="element_2_1" type="text" class="element text" maxlength="255" size="8" value=""
    VB.NET Code:
    Dim hec As HtmlElementCollection = WB1.Document.GetElementsByTagName("iframe")

    On error resume next
    If ele.GetAttribute("title") = "This is some page title - example page title!" Then
    Msgbox "Found!"
    'ele.Document.All("element_2_1").InnerHtml = "test" '//Tried this without success
    End If
    Next

  2. #2
    Lively Member SavedByGrace's Avatar
    Join Date
    May 06
    Posts
    114

    Re: Set Text in textbox within an iframe

    Anyone have any suggestions?

  3. #3
    Lively Member SavedByGrace's Avatar
    Join Date
    May 06
    Posts
    114

    Re: Set Text in textbox within an iframe

    Just a quick update, I still have not found an answer to this, I'd appreciate any suggestions that anyone might have.

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,982

    Re: Set Text in textbox within an iframe

    Perhaps if you were a little less coy about the identity of the webpage in question we could do some investigating?

  5. #5
    Lively Member SavedByGrace's Avatar
    Join Date
    May 06
    Posts
    114

    Re: Set Text in textbox within an iframe

    I am working with a rather unique concept and I am required to guard the details as much as possible. I was hoping that the example HTML code above which mirrors the HTML/iFrame code that I am working with would help illustrate what I am working with. I am not looking for someone to provide exactly working code specific to that site, just suggestions or an example of what may work.

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,982

    Re: Set Text in textbox within an iframe

    The fact is that programming for web interaction is almost never possible without knowing the quirks of the site that one is dealing with. The only general procedure I can recommend is that you don't attempt this in an iframe. If you can load the iframe content as a separate document, manipulate it there and then return it to the iframe that's the only possible route I can suggest without further specifics. But looking at what you have deigned to reveal I'm far from sure that's going to be possible.

    I am working with a rather unique concept and I am required to guard the details as much as possible.
    Yes well, with all due respect, that's what they all say! Very rarely does it prove to be the case that anything is unique or that anybody is 'required' to keep it all secret (unless they're working for the mob!) One thing I do know. There's nothing unique about a project that doesn't work because the programmer doesn't have the necessary skill and is too self absorbed to ask for help. Anyway, I think you can safely assume you've exhausted the extent of any help (to say nothing of the patience) of those of us here so please do not bump this thread again.

  7. #7
    Lively Member SavedByGrace's Avatar
    Join Date
    May 06
    Posts
    114

    Re: Set Text in textbox within an iframe

    -Editted Out-

    God is good.
    Last edited by SavedByGrace; Aug 25th, 2012 at 10:33 PM.

  8. #8
    Hyperactive Member marniel647's Avatar
    Join Date
    Aug 10
    Location
    MSDN Library
    Posts
    256

    Re: Set Text in textbox within an iframe

    Did you also create the iframe code. if you want to set te textbox in your i frame you can change tha value of your iframe code.

  9. #9
    Lively Member SavedByGrace's Avatar
    Join Date
    May 06
    Posts
    114

    Re: Set Text in textbox within an iframe

    Quote Originally Posted by marniel647 View Post
    Did you also create the iframe code. if you want to set te textbox in your i frame you can change tha value of your iframe code.
    That's a good suggestion, but, I don't have any control over the iframe code.

  10. #10
    Hyperactive Member
    Join Date
    Jul 11
    Location
    UK
    Posts
    438

    Re: Set Text in textbox within an iframe

    A web site's HTML code is usually specific to that website, and as dunfiddlin says it is difficult to produce generic code that interacts reliably with specific HTML when you don't know what that specific HTML is.

    With that in mind, the following may work. Or it might not. Or it might do something totally unexpected. That said though, I have had it working with a textbox in an iFrame ... just not your textbox in your iFrame :P


    vb.net Code:
    1. Dim iFramesFound As Boolean = False ' (only used to give feedback)
    2. Dim inputFound As Boolean = False ' (only used to give feedback)
    3.  
    4. 'Find all the frames
    5. Dim frames As HtmlWindowCollection = WebBrowser1.Document.Window.Frames
    6.  
    7. 'check each frame for the element with id="element_2_1"
    8. For f = 0 To frames.Count - 1
    9.     iFramesFound = True ' (feedback, remember?)
    10.  
    11.     Dim frameDoc As HtmlDocument = WebBrowser1.Document.Window.Frames(f).Document
    12.     Dim frameEle As HtmlElement = frameDoc.GetElementById("element_2_1")
    13.     If frameEle IsNot Nothing Then
    14.         inputFound = True ' (also feedback, remember?)
    15.  
    16.         frameEle.SetAttribute("value", "DDDD") ' write into the textbox
    17.         Exit For
    18.     End If
    19. Next
    20.  
    21. '(here comes the feedback):-
    22. Dim strMessage As String
    23. strMessage = IIf(iFramesFound, "Found iFrames", _
    24.                                "NO iFrames found").ToString
    25. strMessage &= Environment.NewLine
    26. strMessage &= IIf(inputFound, "and then found text input box", _
    27.                               "and then failed to find text input box").ToString
    28. MessageBox.Show(strMessage)

  11. #11
    Lively Member SavedByGrace's Avatar
    Join Date
    May 06
    Posts
    114

    Re: Set Text in textbox within an iframe

    Thank you for the example Inferred, I tried it but got an access error, added an "On Error Resume Next" since there were multiple frames, some of which were connected to a different host/site which likely caused the access error. But, it still did not take. I did however, figure out a different work around. I appreciate yours and marniel647's help.

  12. #12
    PowerPoster kevininstructor's Avatar
    Join Date
    Jun 08
    Location
    Oregon
    Posts
    5,067

    Re: Set Text in textbox within an iframe

    If by chance you have control over the content then I would suggest discarding the use of iframe and code the form in the same page. The code below may or may not be more than you are use too in regards to writing web content and if so there are plenty of sites that can assist with learning about css. Of course if you are not able to change how content is done the following is of no use.

    I had a page done and tweaked it to use an iframe then without an iframe. The legend style is setup for IE and if was used in a production environment would have a css style sheet to determine the agent (browser) to conditionally style the legend. Also note for the div in the page with the iframe position is absolute while in the single page relative.

    First example embeds another page in it via iframe while the second example does the same in a single page.

    Example 1
    Mainpage
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    	<title>Untitled</title>
    </head>
    <body>
    	<div style="position:absolute;top:100px;left:100px;">
    	<iframe src="./Page1.html" scrolling="No" frameborder="0" style="width: 548px; height: 150px"></iframe> 
    	</div>
    </body>
    </html>
    iframe for above
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    	<title>MSDN Site Search via Google</title>
    	<style media="screen" type="text/css">
    		fieldset 
    		{
    			border: 1px solid #781351;width: 20em;
    			padding-left: 21px;
    			padding-bottom: 1em;
    			width:348px;
    			position:relative;
    			background-color: #ffff00;
    		}
    		/* legend, postion and top are IE tweaks to ensure background does not bleed */
    		legend {position: relative;top:-0.75em;color: #fff;background: #ffa20c;border: 1px solid #781351;padding: 2px 6px; margin-bottom:15px} 
    		input {color: #781351;background: #fee3ad;border: 1px solid #781351;margin-bottom:10px;}
    		.submit input {color: #000;background: #ffa20f;border: 2px outset #d7b9c9} 
    		span {margin-bottom:10px;color: #DEB887;vertical-align: top;}
    	</style>
    	<script language="javascript" type="text/javascript">
    		function MSDN_Site_Search()
    		{
    			document.write("<a HREF='http://www.google.ca/search?as_q=" + document.mainForm.inputtext1.value + "&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Fmsdn.microsoft.com&as_occt=any&safe=active&tbs=&as_filetype=&as_rights=' title='Return to home page'>" + document.mainForm.inputtext1.value + "</a>");
    		}
    	</script>
    </head>
    <body>
    <form name="mainForm">
    	<fieldset>
    		<legend>MSDN Search</legend>
    		<input type="text" id="inputtext1" value="VB.NET" style="width: 300px;" />
    		<input type="button" value="GO" style="width:332px" onClick="MSDN_Site_Search();"  style="width: 400px;">
    	</fieldset>
    </form>
    </body>
    </html>
    Single page, does same as above
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    	<title>MSDN Site Search via Google</title>
    	<style media="screen" type="text/css">
    		fieldset 
    		{
    			border: 1px solid #781351;width: 20em;
    			padding-left: 21px;
    			padding-bottom: 1em;
    			width:348px;
    			position:relative;
    			left:100px;
    			top:100px;
    			background-color: #ffff00;
    		}
    		/* legend, postion and top are IE tweaks to ensure background does not bleed */
    		legend {position: relative;top:-0.75em;color: #fff;background: #ffa20c;border: 1px solid #781351;padding: 2px 6px; margin-bottom:15px} 
    		input {color: #781351;background: #fee3ad;border: 1px solid #781351;margin-bottom:10px;}
    		.submit input {color: #000;background: #ffa20f;border: 2px outset #d7b9c9} 
    		span {margin-bottom:10px;color: #DEB887;vertical-align: top;}
    	</style>
    	<script language="javascript" type="text/javascript">
    		function MSDN_Site_Search()
    		{
    			document.write("<a HREF='http://www.google.ca/search?as_q=" + document.mainForm.inputtext1.value + "&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Fmsdn.microsoft.com&as_occt=any&safe=active&tbs=&as_filetype=&as_rights=' title='Return to home page'>" + document.mainForm.inputtext1.value + "</a>");
    		}
    	</script>
    </head>
    <body>
    <form name="mainForm">
    	<fieldset>
    		<legend>MSDN Search</legend>
    		<input type="text" id="inputtext1" value="VB.NET" style="width: 300px;" />
    		<input type="button" value="GO" style="width:332px" onClick="MSDN_Site_Search();"  style="width: 400px;">
    	</fieldset>
    </form>
    </body>
    </html>

  13. #13
    Lively Member SavedByGrace's Avatar
    Join Date
    May 06
    Posts
    114

    Re: Set Text in textbox within an iframe

    Thank you for the suggestion kevininstructor. that looks like a great solution, unfortunately, I do not have control over the server's code.

  14. #14
    PowerPoster kevininstructor's Avatar
    Join Date
    Jun 08
    Location
    Oregon
    Posts
    5,067

    Re: Set Text in textbox within an iframe

    Quote Originally Posted by SavedByGrace View Post
    Thank you for the suggestion kevininstructor. that looks like a great solution, unfortunately, I do not have control over the server's code.
    Have you considered talking to the developer for this code?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •