Set default form textfield value (webbrowser control)

Posted by Khou on Stack Overflow See other posts from Stack Overflow or by Khou
Published on 2010-03-17T03:27:45Z Indexed on 2010/03/17 3:51 UTC
Read the original article Hit count: 468

Filed under:
|
|
|

Hi

I would like my application to load a webpage and set default the form textfield value a predefine value.

Requirements:

-The application is a windows form, it is to use the web browser control, to load a web page.

-Textfield values are define by within the application.

-When textfield on the webpage matches the applications predefined elements, the predefine fixed value is set and can not be changed by the end user.

Example If my application defines element "FirstName" equal to value "John", the text field for value for element "FirstName" will always equal "John" and this value can not be changed by the end user.

Below is html/javascript code to perform this functionality, now how do I implement this in a windows form? (without having to modify the loaded webpage source code (if possible).

HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
    <title>page title</title>
    <script script type="text/javascript" src="demo1.js"></script>
</head>
<body onload="def(document.someform, 'name', 'my default name value');">

    <h2 style="color: #8e9182">test form title</h2>
    <form name="someform" id="someform_frm" action="#"> 
    <table cellspacing="1"> 
        <tr><td><label for="name">NameX: </label></td><td><input type="text" size="30" maxlength="155" name="name" onchange="def(document.someform, 'name', 'my default name value');"></td></tr>
        <tr><td><label for="name2">NameY: </label></td><td><input type="text" size="30" maxlength="155" name="name2"></td></tr>
        <tr><td colspan="2"><input type="button" name="submit" value="Submit" onclick="showFormData(this.form);" ></td></table>
    </form>

</body>
</html> 

JAVASCRIPT

function def(oForm, element_name, def_txt) {

oForm.elements[element_name].value = def_txt;


} 

© Stack Overflow or respective owner

Related posts about c#

Related posts about form