Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Access HTML control in Javascript

Reply
Thread Tools

Access HTML control in Javascript

 
 
Ben
Guest
Posts: n/a
 
      06-19-2006
Hi,

I have a ASP page which applied default master page style.

I added a html text control in the ContentPlaceHolder and try to access
it in javascript.
I always got a null value of document.form2.DataType.value.
('document.form2.DataType' is null or not an object)
Could anyone point out error in the following code?

Thanks,

Ben

----------------Begin of ASPX file-----------------
<%@ Page Language="VB" Transaction="Required"
MasterPageFile="~/MasterPage.master" AutoEventWireup="false"
CodeFile="dataPage.aspx.vb" Inherits="DataPage" title="xxxx" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">

<form id="form2">
<div>
<INPUT id="DataType" type=text />
</div>
</form>

<script language="javascript">

function ShowPopup()
{

document.form2.DataType.value = "Raw Data"; //

return true;
}
</script>

</asp:Content>
----------------End of ASPX file-----------------

 
Reply With Quote
 
 
 
 
Ben
Guest
Posts: n/a
 
      06-19-2006
I found that it works with 'document.forms[0].DataType.value'.

Ben

 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      06-19-2006
Hi Ben,

I'm not sure why you're adding a form since ASP.NET already has one. Try
something like this?

<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled
Page" %>
<asp:content id="Content2" runat="Server"
contentplaceholderid="ContentPlaceHolder1">
<div>
<input id="DataType" type="text" />
</div>
<script language="javascript">
document.forms[0].DataType.value = "Raw Data"; //
</script>
</asp:content>


Ken
Microsoft MVP [ASP.NET]


"Ben" <> wrote in message
news: ups.com...
> Hi,
>
> I have a ASP page which applied default master page style.
>
> I added a html text control in the ContentPlaceHolder and try to access
> it in javascript.
> I always got a null value of document.form2.DataType.value.
> ('document.form2.DataType' is null or not an object)
> Could anyone point out error in the following code?
>
> Thanks,
>
> Ben
>
> ----------------Begin of ASPX file-----------------
> <%@ Page Language="VB" Transaction="Required"
> MasterPageFile="~/MasterPage.master" AutoEventWireup="false"
> CodeFile="dataPage.aspx.vb" Inherits="DataPage" title="xxxx" %>
>
> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
> Runat="Server">
>
> <form id="form2">
> <div>
> <INPUT id="DataType" type=text />
> </div>
> </form>
>
> <script language="javascript">
>
> function ShowPopup()
> {
>
> document.form2.DataType.value = "Raw Data"; //
>
> return true;
> }
> </script>
>
> </asp:Content>
> ----------------End of ASPX file-----------------
>



 
Reply With Quote
 
Ben
Guest
Posts: n/a
 
      06-19-2006
Thanks, Ken
Your code works fine. The reason is that I want to access control by
form name instead of form index.

Bin


Ken Cox [Microsoft MVP] wrote:
> Hi Ben,
>
> I'm not sure why you're adding a form since ASP.NET already has one. Try
> something like this?
>
> <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled
> Page" %>
> <asp:content id="Content2" runat="Server"
> contentplaceholderid="ContentPlaceHolder1">
> <div>
> <input id="DataType" type="text" />
> </div>
> <script language="javascript">
> document.forms[0].DataType.value = "Raw Data"; //
> </script>
> </asp:content>
>
>
> Ken
> Microsoft MVP [ASP.NET]


 
Reply With Quote
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      06-20-2006
Hi Ben,

You'd want to use the form name as it was in the master, not a form that you
add yourself. That would just confuse ASP.NET.

Ken

"Ben" <> wrote in message
news: ups.com...
> Thanks, Ken
> Your code works fine. The reason is that I want to access control by
> form name instead of form index.
>
> Bin
>
>
> Ken Cox [Microsoft MVP] wrote:
>> Hi Ben,
>>
>> I'm not sure why you're adding a form since ASP.NET already has one. Try
>> something like this?
>>
>> <%@ Page Language="VB" MasterPageFile="~/MasterPage.master"
>> Title="Untitled
>> Page" %>
>> <asp:content id="Content2" runat="Server"
>> contentplaceholderid="ContentPlaceHolder1">
>> <div>
>> <input id="DataType" type="text" />
>> </div>
>> <script language="javascript">
>> document.forms[0].DataType.value = "Raw Data"; //
>> </script>
>> </asp:content>
>>
>>
>> Ken
>> Microsoft MVP [ASP.NET]

>



 
Reply With Quote
 
JohnPantoo JohnPantoo is offline
Junior Member
Join Date: Sep 2011
Posts: 3
 
      09-21-2011
Hi Everyone,
Here some snippet code for creating html control dynamically in javascript....
<script type="text/javascript"> function createUserInterface() {
document.write("<form id='form1'>");
document.write("Employee Id :&nbsp;&nbsp; <input type='text' id='tt1' /> <br />");
document.write("Employee Name :&nbsp;&nbsp; <input type='text' id='tt2' /><br />");
document.write("Employee Age :&nbsp;&nbsp; <input type='text' id='tt3' /><br />");
document.write("Employee City :&nbsp; <select id='selectCity'><option value='Allahabd'>Allahabd</option>");
document.write("<option value='Lucknow'>Lucknow</option><option value='Kanpur'>Kanpur</option></select><br />");
document.write("<input type='button' id='btnSubmit' value='Submit' />");
document.write("</form>");
}

</script>


for more details please check out the following link......
http://mindstick.com/Articles/ddeb7a...%20dynamically


Thanks !!!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
403 Forbidden: You were denied access because: Access denied by access control list Southern Kiwi NZ Computing 6 03-19-2006 05:19 AM
Help on HTML server control vs HTML control =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?= ASP .Net 5 09-15-2005 07:51 PM
trying to access an embedded html control within a web control Joe Stampf ASP .Net Web Controls 0 12-15-2003 07:31 PM
HTML Client Control versus. HTML Server Control versus. Web Server Control Matthew Louden ASP .Net 1 10-11-2003 07:09 PM
access html control with javascript Salim Afþar ASP .Net Building Controls 0 08-28-2003 09:22 AM



Advertisments