Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

How to Call/Reference a TextBox control on the client side

How do I call or reference a textbox control on the client side.  I have a JavaScript pop-up calendar and it works fine in my classic ASP application but now I cannot work out how to call the textbox, have tried so many combinations.

Here is the some of the code

<td valign="baseline">
<asp:textbox id="PreferredDateA" text='<%# rsViewBookingsDetail.FieldValue("PreferredDateA", Container) %>' TextMode="SingleLine" Columns="32" runat="server" ReadOnly="true" /></td>
<td valign="baseline"><img src="images/calendar.gif" width="22" height="17" border="0" onclick='showCalendar(this, document.all('PreferredDateA'),"dd/mm/yyyy",null,0,-1,305)'>
<asp:RequiredFieldValidator runat="server" ID="date1" ControlToValidate="PreferredDateA" ErrorMessage = "Please select a Preference Date "/></td>

I don't know why .NET does not conform to the DOM model 'document.form1.textbox1....... why do they make it harder not easier.  

I know maybe its b/c its all run at the server but why can't I reference the textbox easily.
0
simonettaj
Asked:
simonettaj
  • 3
  • 3
1 Solution
 
BurntSkyCommented:
You can use this to retrieve the textbox's client-side ID:

<%= this.PreferredDateA.ClientID %>

then you can grab the textbox from the popup using this:

window.opener.document.forms(0).[control's clientid].value = '[new value]';
0
 
simonettajAuthor Commented:
Okay so how could I integrate this into the below part I need it to be an onclick event of the image tag.

'showCalendar(this, document.all('PreferredDateA'),"dd/mm/yyyy",null,0,-1,305)'>

Could I put this in <%= this.PreferredDateA.ClientID %>

'showCalendar(this, document.all('<%= this.PreferredDateA.ClientID %>'),"dd/mm/yyyy",null,0,-1,305)'>

Thanks

0
 
Ramesh SrinivasTechnical ConsultantCommented:
To reference an asp.net control you can use:

document.getElementById("ControlID").value

regards,

KS

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
BurntSkyCommented:
If you want to pass the reference to the textbox, use this:

<img ... onclick='showCalendar(this, document.getElementById("<%= PreferredDateA.ClientID %>"),"dd/mm/yyyy",null,0,-1,305)'>
0
 
simonettajAuthor Commented:
Hi BurntSky

I copied and pasted your line of code and it came back with object expected error .

Is there something missing?

Here is the web page if you want to see what is happening.....

http://www.eskape.com.au/VoucherDetail.aspx?VoucherNumber=1000000006
0
 
BurntSkyCommented:
Very strange.  I saved the generated .aspx and the popcalendar.js files to my machine and opened it in IE.  It works fine.

This leads me to believe that there's some other problem... a confliction of some sort with another javascript function maybe?  Try making a copy of the page and eliminating pieces of it until the problem disappears.

If it wasn't 2:30am here and this question was worth more than 125 points I might be of more help.  If I think of something else, I'll let you know.
0
 
simonettajAuthor Commented:
Thanks burnt sky it works I have in include the JavaScript code within the page itself and not as a reference file for some reason.

Regards,
James Simonetta.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now