locked
If I have a comboBox named cbxFullName. If someone types text into it, how do I get the text that was typed in with cleint side script? RRS feed

  • Question

  • User-858993849 posted

    How do I get the text typed in a combobox from the client side. Not the text from a list item it finds, but the actual text that a user types in?

    Monday, July 7, 2014 11:11 PM

Answers

  • User-1360095595 posted

    This took a bit of digging in the combobox code.

    I don't know if this is the right/best way, but it worked for me:

    var combo = $find('<%= ComboBox1.ClientID %>');
    var tb = combo.get_textBoxControl();
    alert(tb.value);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2014 1:30 AM
  • User-1360095595 posted

    (Thanks, I've moved your thread. "Alert Moderators" link in the future to ask for such things).

    Well I ran the code on a button click. So my question to you is based on what event do you want to run the code? 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2014 9:40 AM
  • User-1360095595 posted

    That's what I was going to suggest (hiddenfield) :) So you need to do that in the onchange event then? You don't click a button to submit your page or something like that?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2014 10:14 AM
  • User-1360095595 posted

    Ooo! Interesting. I don't use Chrome and, yes, tested on IE only. But the code I provided should work on all browsers (?). Do you see the alert message (add it in temporarily if needed).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2014 10:23 AM
  • User-1360095595 posted

    Let me make sure I understand. You get this error as a result on using the code I provided, or you get the error regardless? If you content out the code I provided, all's well? 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2014 10:34 AM
  • User-1360095595 posted

    Then perhaps to keep the thread focused you can create a new thread since this is unrelated to the title of this thread. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2014 10:47 AM

All replies

  • User-1360095595 posted

    This took a bit of digging in the combobox code.

    I don't know if this is the right/best way, but it worked for me:

    var combo = $find('<%= ComboBox1.ClientID %>');
    var tb = combo.get_textBoxControl();
    alert(tb.value);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2014 1:30 AM
  • User-858993849 posted

    Thanks, you're the best. By the way, someone told me I needed to create the question in the other forum that you deleted, so I did it. 

    What event can I use ClientSide from the Combobox to run the above script?

    I tried onblur with Chrome, but it doesn't do anything. With Internet Explorer, I get an error.

    Tuesday, July 8, 2014 8:53 AM
  • User-1360095595 posted

    (Thanks, I've moved your thread. "Alert Moderators" link in the future to ask for such things).

    Well I ran the code on a button click. So my question to you is based on what event do you want to run the code? 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2014 9:40 AM
  • User-858993849 posted

    I didn't take offense to your moving it, you are a professional and so I didn't have the slightest problem with it.  I like that you are keeping an eye on things.

    What I am trying in the end to get is the text typed into the combobox when it isn't a match with text in a listItem of the combobox.  In codebehind, running an "onTextChanged" event, I actually get the value of the item at index 0 when I try to get the .text part of the combobox.  i.e. dim txtTemp as string = combobox.text.  txtTemp doesn't come back with the text in the combobox, it always comes back with the value of the first list time, not even the text of it.

    So what I am trying to do now is to get the text typed in the Combobox client side, save it to a HIddenField, and then grab it in codebehind after the PostBack using the onTextChanged event.

    I hope that make sense!

    Tuesday, July 8, 2014 10:06 AM
  • User-1360095595 posted

    That's what I was going to suggest (hiddenfield) :) So you need to do that in the onchange event then? You don't click a button to submit your page or something like that?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2014 10:14 AM
  • User-858993849 posted

    That is what I was trying to do, but it did nothing. I just now realized I hadn't tried it in Internet Explorer, and it worked fine. But it doesn't do anything in Chrome.  Any ideas on how to get it to work in Chrome?

    Tuesday, July 8, 2014 10:19 AM
  • User-1360095595 posted

    Ooo! Interesting. I don't use Chrome and, yes, tested on IE only. But the code I provided should work on all browsers (?). Do you see the alert message (add it in temporarily if needed).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2014 10:23 AM
  • User-858993849 posted

    The reason I went to Chrome was that I was getting the error "Unable to get property 'createRange' of undefined or null reference" and noticed it went away when using Chrome.

    Now that I am back using Internet Explorer, I noticed that in debug, the control works fine, but when not in debug, I have the same error.

    Any ideas?

    Tuesday, July 8, 2014 10:25 AM
  • User-858993849 posted

    Yes, it works perfectly, the alert shows the text form the textbox (you're a genius), everything works fine in debug now. But out of debug, I get this error and it won't work.

    Unable to get property 'createRange' of undefined or null reference

    Tuesday, July 8, 2014 10:26 AM
  • User-1360095595 posted

    Let me make sure I understand. You get this error as a result on using the code I provided, or you get the error regardless? If you content out the code I provided, all's well? 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2014 10:34 AM
  • User-858993849 posted

    I get the error just creating the control and typing any text into the combobox. No your code is fine. Sorry I didn't draw the distinction.

    Tuesday, July 8, 2014 10:38 AM
  • User-1360095595 posted

    Then perhaps to keep the thread focused you can create a new thread since this is unrelated to the title of this thread. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 8, 2014 10:47 AM
  • User-858993849 posted

    Sounds good. I marked all of your answers correct, because they were!  Thanks again for your help!

    Tuesday, July 8, 2014 10:49 AM