Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 14, 2012 03:39 AM by asteranup
Participant
1252 Points
1896 Posts
Feb 13, 2012 03:12 AM|LINK
I have several controls wtih only one part of the middle being different and but want to use one function to handle all of them.
I have tried to do the following:
I have a textbox called TxtAddDriverModel and another one called TxtAddPassengerModel
I am trying to access the two different textboxes by inserting the clubType in the string but it doesn't work. What do I do?
var Type = 'Driver'
if (!($("#<%=TxtAdd" + Type + "Model.ClientID %>").val() == 'Add New MODEL Here!'))
Star
7756 Points
1626 Posts
Feb 13, 2012 03:36 AM|LINK
JAYHAWKER var Type = 'Driver' if (!($("#<%=TxtAdd" + Type + "Model.ClientID %>").val() == 'Add New MODEL Here!'))
hi try this
var Type="Driver";
var id="#txtadd"+Type+"<%=Model.ClientID %>";
if(!$(id).attr('value')=='Add New Model Here')
{
// Execute code
}
All-Star
30184 Points
4906 Posts
Feb 13, 2012 05:02 AM|LINK
Hi,
Try this-
var Type = 'Driver' if (!($('input[id*=TxtAdd' + Type + 'Model]').val() == 'Add New MODEL Here!'))
Feb 13, 2012 02:31 PM|LINK
Thanks!
Using the new notation, how would i get the value of a dropdownlist.
For example, I would use the following before:
if ($("#<%=ddlMake.ClientID %> option:selected").val() == -1)
Feb 13, 2012 03:05 PM|LINK
JAYHAWKER if ($("#<%=ddlMake.ClientID %> option:selected").val() == -1)
if ($("select[id*=ddlMake]").val() == -1)
Feb 13, 2012 04:17 PM|LINK
Thanks, that worked great.
How do I handlle the same thing for textobx, hiddenfield, and label.
i.e, is it input [id*=.....
or text[id*=.....
or select[id*=....
and for a div, what is it?
Feb 13, 2012 04:37 PM|LINK
It is $('tagname[id=tagid]. There can be a lots of combinations. You should study attribute selector. check the following for detail-
http://api.jquery.com/category/selectors/attribute-selectors/
Feb 13, 2012 05:26 PM|LINK
Feb 14, 2012 03:39 AM|LINK
You always need to check the rendered html content to work with jQuery.
JAYHAWKER
Participant
1252 Points
1896 Posts
How do I insert a variable into a the name of a control using Jquery
Feb 13, 2012 03:12 AM|LINK
I have several controls wtih only one part of the middle being different and but want to use one function to handle all of them.
I have tried to do the following:
I have a textbox called TxtAddDriverModel and another one called TxtAddPassengerModel
I am trying to access the two different textboxes by inserting the clubType in the string but it doesn't work. What do I do?
var Type = 'Driver'
if (!($("#<%=TxtAdd" + Type + "Model.ClientID %>").val() == 'Add New MODEL Here!'))
vinay13mar
Star
7756 Points
1626 Posts
Re: How do I insert a variable into a the name of a control using Jquery
Feb 13, 2012 03:36 AM|LINK
hi try this
var Type="Driver";
var id="#txtadd"+Type+"<%=Model.ClientID %>";
if(!$(id).attr('value')=='Add New Model Here')
{
// Execute code
}
V.K.Singh
asteranup
All-Star
30184 Points
4906 Posts
Re: How do I insert a variable into a the name of a control using Jquery
Feb 13, 2012 05:02 AM|LINK
Hi,
Try this-
var Type = 'Driver' if (!($('input[id*=TxtAdd' + Type + 'Model]').val() == 'Add New MODEL Here!'))Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
JAYHAWKER
Participant
1252 Points
1896 Posts
Re: How do I insert a variable into a the name of a control using Jquery
Feb 13, 2012 02:31 PM|LINK
Thanks!
Using the new notation, how would i get the value of a dropdownlist.
For example, I would use the following before:
if ($("#<%=ddlMake.ClientID %> option:selected").val() == -1)asteranup
All-Star
30184 Points
4906 Posts
Re: How do I insert a variable into a the name of a control using Jquery
Feb 13, 2012 03:05 PM|LINK
Hi,
Try this-
if ($("select[id*=ddlMake]").val() == -1)Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
JAYHAWKER
Participant
1252 Points
1896 Posts
Re: How do I insert a variable into a the name of a control using Jquery
Feb 13, 2012 04:17 PM|LINK
Thanks, that worked great.
How do I handlle the same thing for textobx, hiddenfield, and label.
i.e, is it input [id*=.....
or text[id*=.....
or select[id*=....
and for a div, what is it?
asteranup
All-Star
30184 Points
4906 Posts
Re: How do I insert a variable into a the name of a control using Jquery
Feb 13, 2012 04:37 PM|LINK
Hi,
It is $('tagname[id=tagid]. There can be a lots of combinations. You should study attribute selector. check the following for detail-
http://api.jquery.com/category/selectors/attribute-selectors/
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog
JAYHAWKER
Participant
1252 Points
1896 Posts
Re: How do I insert a variable into a the name of a control using Jquery
Feb 13, 2012 05:26 PM|LINK
asteranup
All-Star
30184 Points
4906 Posts
Re: How do I insert a variable into a the name of a control using Jquery
Feb 14, 2012 03:39 AM|LINK
Hi,
You always need to check the rendered html content to work with jQuery.
Anup Das Gupta
Mark as Answer if you feel so. Visit My Blog