Sunday, 15 August 2010

javascript - Can't retrieve selected value from dropdown in dialog using jquery -



javascript - Can't retrieve selected value from dropdown in dialog using jquery -

i have dialog popup few fields in them. dialog retrieved php file. can val() of them dropdowns.

snippets:

call dialog:

$('#createnote').click(function(e){ e.preventdefault(); $.ajax({ url: 'functions.php', type: 'post', data: {"function": "createnotedialog"}, success: function(data){`enter code here` $('#dialog-form').html(data); $('#dialog-form').dialog('open');} }); });

generate form:

if ($func == "createnotedialog" ){ echo '<form class="cmxform"><fieldset>'; echo '<li><label for="category">category</label><select id="inputcategory" class="text ui-widget-content ui-corner-all">'; $r_categories = mysqli_query($global_dbh,'select category pledges.patchcategories order 1 asc'); $first_row = mysqli_fetch_row($r_categories); echo '<option value="' . $first_row[0] . '" selected>' .$first_row[0] . '</option>'; while(($row = mysqli_fetch_array($r_categories)) != false) echo '<option value="' . $row[0] . '">' .$row[0] . '</option>'; echo '</select>'; echo '<label for="version">version </label><select id="inputversion" class="text ui-widget-content ui-corner-all">'; $r_versions = mysqli_query($global_dbh,'select version pledges.patchversions order 1 desc'); $first_row = mysqli_fetch_row($r_versions); echo '<option value="' . $first_row[0] . '" selected>' .$first_row[0] . '</option>'; while(($row = mysqli_fetch_array($r_versions)) != false) echo '<option value="' . $row[0] . '">' .$row[0] . '</option>'; echo '</select>'; echo '<li><label for="devnote">dev note </label><textarea id="inputdevnote" name="devnote" cols=60 rows=7></textarea></li>'; echo '<li><label for="buildnote">build note </label><textarea id="inputbuildnote" name="buildnote" cols=60 rows=7></textarea></li>'; echo '<li><label for="comment">comment </label><textarea id="inputcomment" name="comment" cols=60 rows=6></textarea></li>'; echo '</fieldset></form>'; }

saving:

$( "#dialog-form" ).dialog({ autoopen: false, height: 700, width: 800, modal: true, buttons: { "create note": function() { $.post( "functions.php" , { "function": "savenote" , "version": $("#inputversion").val(), "category": $('#inputcategory').val() ,"devnote": $('#inputdevnote').val() ,"buildnote": $('#inputbuildnote').val() ,"comment": $('#inputcomment').val()}); patchnotestable.fndraw(); $( ).dialog( "close" ); }, "cancel": function() { $( ).dialog( "close" ); } }, close: function() { $(this).dialog('close'); } });

for reason $('#inputcategory').val() , $('#inputversion').val() empty, while text area's fine.

also tried adding onchange function alert changes dropdown ... wouldn't fire.

the form seems generated correctly:

<li><label for="category">category</label><select id="inputcategory" class="text ui-widget-content ui-corner-all">

just can't figure out why can't grab values :)

try this.

create <div class="loop">...</div> within dialog box. , set your stuff within "loop".

after seek reload partition after ajax, after click

$('#createnote').click(function(e){ e.preventdefault(); $.ajax({ ... ... ... }); $(".loop").load("functions.php .loop", {"function": "savenote" , "version": $("#inputversion").val(), "category": $('#inputcategory').val() ,"devnote": $('#inputdevnote').val() ,"buildnote": $('#inputbuildnote').val() ,"comment": $('#inputcomment').val()}); });

javascript php jquery html

No comments:

Post a Comment