Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radiobutton function in javascript Please help

Status
Not open for further replies.

canasdaq

Programmer
Mar 13, 2003
3
US
I have a radiobtton and textbox associated with it.

<asp:RadioButtonList ID="DBACd" runat="server" RepeatDirection="Horizontal" >
<asp:ListItem Text="Doing Business As: or" Value="D" />
<asp:ListItem Text="Optional Name" Value="O" Selected="true" />
</asp:RadioButtonList>



<asp:TextBox runat="server" MaxLength="20" Width="90%" ID="DBAName" CssClass="fdata"></asp:TextBox>


when i click on 1st item, the text box should be populated with first 3 letters as "DBA" and then the customer should be able to enter the rest of the field. When we navigate off the page, this value will be saved to the database and when we come back to the page the value saved in the database will be displayed in the textbox with 1st being selected.

When i click on the 2nd item, the textbox should be balnked out totally.


Can anyone please help me. I've written the javascript in onclick which is not doing the correct thing. Can anyone please help me where i am doing wrong. I need this immediately.

function ShowHideDBA()
{
if (document.getElementById("<%=DBACd.ClientId %>"))
{
if (document.getElementById("<%=DBACd.ClientId %>" + "_0").checked)
{
// start 1.02
//document.getElementById("<%=DBAName.ClientId %>").value ="DBA";
if (document.getElementById("<%=DBAName.ClientId %>").value != "")
{
document.getElementById("<%=DBAName.ClientId %>").value = document.getElementById("<%=DBAName.ClientId %>").value;
}
else
{
document.getElementById("<%=DBAName.ClientId %>").value ="DBA";
}
// end 1.02
}
else
{
if ((document.getElementById("<%=DBAName.ClientId %>").value != "") && (document.getElementById("<%=DBAName.ClientId %>").value != "DBA"))
{
document.getElementById("<%=DBAName.ClientId %>").value = document.getElementById("<%=DBAName.ClientId %>").value;
}
else
{
document.getElementById("<%=DBAName.ClientId %>").value ="";
}
}
}
else
{
document.getElementById("<%=DBAName.ClientId %>").value ="";
}
}
 
Given you are asking for client-side help, can you at least post client-side code, not .net stuff that is nothing like the end result?

I need this immediately.

Perhaps you should consider going somewhere and hiring a developer, then.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
I did not mean to say it abruptly. I was just asking for help. And also i posted the javascript function that i have written and asking for giudance where i was doing wrong. And also given the asp.net fields just in case it will be useful for the person looking at the function i've written. I belive we come to the forums so we can get some help from the experienced developers since i am not that experienced in this field.

This is what i have originally posted:
"Can anyone please help me. I've written the javascript in onclick which is not doing the correct thing. Can anyone please help me where i am doing wrong. I need this immediately.

function ShowHideDBA()
 
Hi

canasdaq said:
And also i posted the javascript function that i have written and asking for giudance where i was doing wrong.
No, you not posted any JavaScript function. You posted ASP code which will generate JavaScript code after the ASP interpreter executes it.


Feherke.
 
We really need the resultant code, after all the ASP has been parsed to be able to debug ths.

I would also suggest you check for any errors that may be popping up. I using IE look at the yellow shield icon on the bottom left corner of the browser. If there are any errors double clicking it should bring up the error console.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
And also i posted the javascript function that i have written

Yes, but as has already been pointed out, and which is what I suggested you post, it is NOT the client-side code the browser sees. Suggest posting that.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
[0] If your aspx is written in c#,
[tt] clientId[/tt]
should be read
[tt] client[red]ID[/red] (c#)[/tt]
If it is in vb, then it would be fine.

[1] The client-side function ShowDBA(), though written in a way that looks clumsy and with some approach like a=a assignment kind of line of doubtful taste, should work somehow.

[1.1] The problem probably stamped by the way you set up the click event handler. It appears nowhere in the script shown, why? In any case, it can be assigned to asp:ListItem. In particular, not to be assigned to asp:RadioButtonList.
[tt]
<asp:RadioButtonList ID="DBACd" runat="server" RepeatDirection="Horizontal" >
<asp:ListItem Text="Doing Business As: or" Value="D" [blue]onclick="ShowDBA()"[/blue] />
<asp:ListItem Text="Optional Name" Value="O" Selected="true" [blue]onclick="ShowDBA()"[/blue] />
</asp:RadioButtonList>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top