views:

478

answers:

4

Hi,

I am using the following code:

<div class="example">
    <p> <a href="#info" rel="facebox">View Facebox</a> </p>
    <p>  <input id="Button1" type="button" value="button" onclick="Get_Value();"/></p>  
</div>

<div id="info" style="display:none;">
<p><input id="text1" name="text1" type="text" value="abc"/></p>
<p>  <input id="Button2" type="button" value="button" onclick="Get_Value();$.facebox.close(); return;"/>    </p>

<script type="text/javascript">
function Get_Value()
{
 alert($('#text1').val());

 var myTextField = document.getElementById('text1');
 alert("You entered: " + myTextField.value)
}
</script>

The problem is that, in my alert statements, I am always getting the initial value 'abc' for the textbox text1; but not any value that is entered by the user when it is opened inside a facebox. Can anybody please help me out?

A: 

Hmm, using jQuery 1.3.2 your example doesn't seem to display the FaceBox area when clicking on the link (it stays invisible). I modified your example slightly with the following View Facebox link and now the FaceBox shows properly, as well as having the dialog display the current information (in both Safari and Firefox). Does this help?

<a href="#" onClick="javascript:$('#info').show(); return false;" rel="facebox">View Facebox</a>
Gene Goykhman
hi, I am running this code in IE 7.0 and it seems to be working fine here. Did not yet try running it on mozilla. I am also using the same version jquery 1.3.2.Anyways thanks for the reply :-)
Hari
Ok, but have you tried making the tag change I suggested? It should solve your problem in IE7 as well.
Gene Goykhman
A: 

Try with alert($('.content #text1').val());, this is because facebox is creating a "copy" of your dive in a table to display its "box" and keep the same ids (you can see that happening with Firebug)

Edit: working Firefox, Chrome and IE7 example:

<html>
<head>
    <title>unable to get value from textbox used inside a facebox</title>
    <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="facebox/facebox.js"></script>
    <link rel="stylesheet" src="facebox/facebox.css"/>
    <script type="text/javascript">
    jQuery(document).ready(function($) {
        $('a[rel*=facebox]').facebox();
    });

    function Get_Value() {
        alert($('#facebox input:first').val());
    }
    </script>
</head>
<body>
    <div class="example">
        <p><a href="#info" rel="facebox">View Facebox</a></p>
        <p><input id="Button1" type="button" value="button"
                  onclick="Get_Value();"/></p>
    </div>

    <div id="info" style="display:none;">
        <form>
            <input name="text1" type="text" />
            <input type="button" value="button" 
                   onclick="Get_Value();$.facebox.close();"/>
        </form>
    </div>
</body>
</html>
RC
hi, am afraid, I tried using alert($('.content #text1').val());but it always gives the output in alert message as "undefined."
Hari
This works for me with jQuery 1.3.2 and Firefox 3.6 but thje way this plugin works is bad IMHO. I can reproduce the "not working" on IE7
RC
Thanks a lot to you also. You got it right.Regards,Hari
Hari
A: 

Hi All,

I got the solution.

I used the following:

alert($('#facebox input:text:first').val())

It gives the modified value of textbox.

Reference: http://stackoverflow.com/questions/1692628/getting-value-of-an-element-inside-facebox-div-using-jquery

Anyways, thanks to all of you...

Hari
A: 

Hi, i am having this same issue using IE7 and jqery 1.4 problem is : i have a popup like this :

<div id="model_content_savefilter" style="display:none;"> <div style="display:none;" id="SaveFilterErrorMessage" class="errorMessage"></div>

<table id="save_filter_modal" cellpadding="0" cellspacing="0" border="0"> <tr><td > You are saving a filter that shows balances for </td></tr>
<tr><td > Please choose a name for your filter </td></tr>
<tr><td ><input id="saveFilterTxt" name="saveFilterTxt" type="text" value=""/></td></tr> <tr><td > <input type = "button" onclick="javascript:saveFavourite('operateOnFavouriteFilter.htm',1,'','H')" value ="Save"/></td> <td width="20%"> <a href = "#" id="cancelFilter" >Cancel</a> </td> </tr>
</table> </div>

and Javascript function is like this function saveFavourite(action, id,queryString,inputTxtValue) { alert("hi :"); alert($('#model_content_savefilter input[type=text]:first').val()); alert("val :" + document.getElementById("saveFilterTxt").value); }

every time value is coming empty Pls hel

tarun k