javascript - How to pass value to JS function and, then, to PHP script -
i want show result of php script on div tag without page refresh. have list of .c files (the users can compile them on server)...
<option value="" selected="selected">choose file </option>'; $dirpath = dir('directoryexample'); while (($file = $dirpath->read()) !== false) { if ($file == '.' || $file == '..') continue; echo "<option value=\"" . trim($file) . "\">" . $file . "\n"; } $dirpath->close(); echo '</select>
...and 2 div , button this:
<div id="2" style="display:none;"> </div> <div id="1" style="display:visible;"> compile...</div> <button type="button" onclick="codiad.ccomp.compile(this.value);">compile</button>
first question: how can pass selected file jquery function? this.value works fine?
this jquery function:
compile: function(value) { if(($('#1').css('display')!='none')){ $('#2').load(this.path+'\compile.php').show().siblings('div').hide(); }else if($('#2').css('display')!='none'){ $('#1').show().siblings('div').hide(); } }
the code works fine second question: how can pass value php page?
thanks in advance!
you can pass data argument .load()
.
$('#2').load(this.path+'/compile.php', { file: $("#selectid").val() }) .show().siblings('div').hide();
in php script, use $_get['file']
selected filename.
Comments
Post a Comment