2

On my visualforce page there is an input text field and two buttons.I am trying to hit the second button on my page with the 'enter' key by calling a javascript on text field, where in my target is on my seccond button. I am trying to access the button id using $Component notation, however everytime its value is null. Tried using the nested ids but didn't work.

Any useful links or suggestions are appreciated.

Below is my visualforce pageenter image description here

1
  • Nazi, know that you can copy/past code and use the {} button in the editor to format it as a code block. That's more readable than an image. Commented Jul 4, 2014 at 7:36

1 Answer 1

2

The $Component notation is quite picky about the correct number of prefixes etc. I used to build this up in baby steps and check the page source each time to see if the $Component renders anything or is blank.

These days I use a JQuery selector to find the element that ends with the particular id - that way I don't have to worry about the prefixes.

I include JQuery from a CDN, but you could load it as a static resource :

<apex:includescript 
      value="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" />

and then use an ends with selector as follows:

if (keyCode==13)
{
   $('[id$=Auth_id]').click();
}

The key aspect of the selector is the [id$=Auth_id] this translates to 'the element with an id that ends with Auth_id'. I've also used the JQuery click method to chain the button click.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.