Using PHP and Javascript in onblur function -


so have form:

<form enctype="multipart/form-data" action="cgi-bin/upload.cgi?upload_id=" method="post" onsubmit="return startupload(this);" target="xupload"> <table>     <tr>         <td class="first"><span class="right">upload file: </span></td>         <td class="second"><input name="file_1" type="file" onchange="checkext(this.value)" accept=".mp4, .avi, .wmv, .mov, .camrec, .flv, .zip, .rar"></td>         <td class="third"><span class="left">(required)</span></td>     </tr>     <tr></tr>     <tr><center><h2>video information</h2></center></tr>     <tr></tr>     <tr>         <td class="first"><span class="right">your name: </span></td>         <td class="second"><input type="text" name="name"></td>         <td class="third"><span class="left">(preferred)</span></td>     </tr>     <tr>         <td class="first"><span class="right">series id: </span></td>         <td class="second"><input id="series_id" type="text" name="series_id" placeholder="you should have been given admin"></td>         <td class="third"><span class="left">(preferred)</span></td>     </tr>     <tr>         <td class="first"></td>         <td class="second"><span id="series_id_check">enter you're series id above , change</span></td>         <td class="third"></td>     </tr>     <tr>         <td class="first"><span class="right">title: </span></td>         <td class="second"><input type="text" name="title"></td>         <td class="third"><span class="left">(preferred)</span></td>     </tr>     <tr>         <td class="first"></td>         <td class="second center"><small>please use "<span style="color:#9c0000">&lt;br&gt;</span>" make new line</small></td>         <td class="third"></td>     </tr>     <tr>         <td class="first"><span class="right">description: </span></td>         <td class="second"><textarea name="desc"></textarea></td>         <td class="third"><span class="left">(preferred)</span></td>     </tr>     <tr>         <td class="first"><span class="right">guests: </span></td>         <td class="second"><input type="text" name="guests"></td>         <td class="third"><span class="left">(optional)</span></td>     </tr>     <tr>         <td class="first"><span class="right">additional tags: </span></td>         <td class="second"><input type="text" name="tags"></td>         <td class="third"><span class="left">(comma separated - optional)</span></td>     </tr> </table> <input type="submit" name="submit" value="upload file"> </form> 

which use upload videos web hosting server. want able change text in series_id_check span javascript uses php arrays... here's php use populating arrays mysql (i know depreciated web hosting php 5.3 installed , depreciated 5.4):

$sql1 = mysql_fetch_assoc(mysql_query("select count cnt series")); $count = $sql1['cnt'];  $gamearray = array($count - 1); $namearray = array($count - 1); $idarray = array($count - 1);  ($i = 0; $i < $count; $i++) {     $sql2 = mysql_fetch_assoc(mysql_query("select id,game,name series id='{$i}'"));      $gamearray[$i] = $sql2['game'];     $namearray[$i] = $sql2['name'];     $idarray[$i]   = $sql2['id']; } 

i know connects database fine i've got die statement when tries connect

the javascript is:

var id = "series_id";  document.getelementbyid("series_id").onblur = function() {     var value = document.getelementbyid(id).value;       var gamearray = new array(<? echo implode(',', $gamearray); ?>;     var namearray = new array(<? echo implode(',', $namearray); ?>;     var idarray = new array(<? echo implode(',', $idarray); ?>;      if (inarray(value,idarray)     {         var id = parceint(value);         var game = gamearray.indexof(id);         var name = namearray.indexof(id);         var input= "you've inputted id game: " + game + " series: " + name;          document.getelementbyid("spawn_series_id_check").innerhtml = input;     } });  function inarray(var input, var array) {     var count = array.length;     var returnval = false;      (var = 0; < count; i++)     {         if (array[i] == input)         {             returnval = true;         }     }      return returnval; } 

basically text in series_id_check doesn't change. tell me how fix it

you should consider using json handle these data.

$result = mysql_query("select id,game,name series"); $count = count($result);  $series = array();  while ($row = mysql_fetch_assoc($result)) {     $series[$row['id']] = array('game' => $row['game'], 'name' => $row['name']); } 

and @ js:

document.getelementbyid("series_id").onblur = function() {     var series = '<?php echo json_encode($series); ?>';     var id = parseint(this.value, 10);      if (undefined !== series[id])     {         var game = series[id]['game'];         var name = series[id]['name'];          var message = "you've inputted id game: " + game + " series: " + name;          document.getelementbyid("spawn_series_id_check").innerhtml = message;     } }); 

i haven't tested code, way should go.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -