views:

77

answers:

1

Hi,

I have a iFrame which i load into jquery dialog.

I want to focus an element inside the iFrame whenever the Jquery Dialog is being opened.

Here is the code i am using to attach iframe to Dialog.

$("<div id=\"srch" + options.winId + "\" title=\"" + options.windowTitle + "\" style=\"padding-left:0px;padding-right:0px;padding-top:0px\" tabindex=\"-1\"><iframe src=\"" + url + "\" id=\"frame" + options.winId + "\" name=\"frame" + options.winId + "\" height=\"100%\" width=\"100%\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\" tabindex=\"-1\"></div>").appendTo("body")
//Now initialize a Dialog Window
$('#srch' + options.winId).dialog({
    autoOpen: (options.searchText == '') ? true : false,
    height: options.height,
    width: options.width,
    modal: options.isModal,
    closeOnEscape: true,
    open: function () {
    },
    close: function () {
        $('#srch' + options.winId).remove();
    }
});

I have written this code inside the page which isopened through iFrame src.

$(document).ready(function () {
    $('input1').focus().select();
});

How can i achieve this?

Thanks, Huzefa

A: 

There is one thing in your statement I noticed

$('input1').focus().select();

"input1" should either be an id or a class, so you need to select it with a "." or a "#". Like

$('#input1').trigger('focus');

If you don't have an id or a class you need a pseudo selector like ":input", which querys all input elements on your page. You may combine it with another pseudo selector, for instance

$(':input:first')

will only query the first input element.

jAndy