0

Hey guys, I'm a noob in javascript and want to know what I'm doing wrong. What I'm trying to do basically is hava a select menu determine where my strings are to be stored. Here is what I'm doing:

The code:

<form id="form1" name="form1" method="post" action="push.php">
<select name="ga" id="ga" onchange="gameApp(this);">
    <option value="game">Game</option>
    <option value="app">App</option>
    </select><br/>
  App/Game Name:
  <input type="text" name="n" id="n" />
  *<br />
  Author:
  <input type="text" name="a" id="a" />
  *<br />
  Version:
  <input type="text" name="v" id="v" />
  <br />
  Icon:
  <input type="text" name="i" id="i" />
  *<br />
  Download Link:
  <input type="text" name="l" id="l" />
  *<br />
  Description:
  <input type="text" height="80px" name="d" id="d" />
  <br />
  Screenshot:
  <input type="text" name="s" id="s" /><br />
  <input type="text" name="s2e" id="s2e" /><br />
  <input type="text" name="s3" id="s3" /><br />
  <input type="text" name="s4" id="s4" /><br />
  <input type="text" name="s5" id="s5" />
  <br />
  App Size (MB):
  <input type="text" name="s2" id="s2" />
  <br />
  Original Link (windows market, itunes, etc):
  <input type="text" name="o" id="o" />
  <br />
    Device Profile
  <input type="text" name="device" id="device"/>
  *
  <input type="submit" name="submit" id="submit" value="Submit" />
</form>
<?php

// Fetch APP DETAILS
$n = stripslashes($_POST['n']);
$a = stripslashes($_POST['a']);
$v = stripslashes($_POST['v']);
$i = stripslashes($_POST['i']);
$l = stripslashes($_POST['l']);
$d = stripslashes($_POST['d']);
$s = stripslashes($_POST['s']);
$s2e = stripslashes($_POST['s2e']);
$s3 = stripslashes($_POST['s3']);
$s4 = stripslashes($_POST['s4']);
$s5 = stripslashes($_POST['s5']);
$s2 = stripslashes($_POST['s2']);
$o = stripslashes($_POST['o']);
$device = stripslashes($_POST['device']);
if($n != ""){
// Create the file
$file = 
"\n"
 . $n . "(.)\n"
 . $a . "(.)\n"
 . $v . "(.)\n"
 . $i . "(.)\n"
 . $l . "(.)\n"
 . $d . "(.)\n"
 . $s . "(.)\n"
  . $s2e . "(.)\n"
   . $s3 . "(.)\n"
    . $s4 . "(.)\n"
     . $s5 . "(.)\n"
 . $s2 . "(.)\n"
 . $o . "(.)\n"
 . $device . "(.)";
}


?>
<!-- The part that doesnt work-->
<script type="text/javascript">
function gameApp(selection) {
  if (selection.value === "app") {
        document.write(<?php file_put_contents('../apps/page1/raw_data.txt', $file, FILE_APPEND);?>));}
    if (selection.value=== "game"{
        document.write(<?php file_put_contents('../games/page1/raw_data.txt', $file, FILE_APPEND);?>));}
}


    </script>

Thanks in advance

3
Contributors
8
Replies
11
Views
4 Years
Discussion Span
Last Post by urtrivedi
0

Edit: I forgot to mention that the above code posts the data in both text files.

0

@persianprez

Hey guys, I'm a noob in javascript and want to know what I'm doing wrong. What I'm trying to do basically is hava a select menu determine where my strings are to be stored.

May I ask why are you using this stripslashes that many times? Can't you used put it in an array and echo out stripslashes one by one?

Technically,you don't need that javascript code to select strings. You can just used php to print or echo it out.

0

I used the stripslashes just because it worked and I left it at that for now. I'm not sure I understand your alternative for the javascript code

0

@persianprez

I used the stripslashes just because it worked and I left it at that for now. I'm not sure I understand your alternative for the javascript code

You mean it's writing the strings on the txt file? You mention it's the javascript code is not working? If it's not working how can it write the data on the txt file?

The php part (the code on the bottom) I can understand but the javascript part I don't

<?php file_put_contents('../apps/page1/raw_data.txt', $file, FILE_APPEND);?>

What is the issue?

Edited by LastMitch: grammer

0

My IF statement isn't working (or maybe its my entire function). When I run the code and fill in the form, the form is submitted to both text files because the if statement isn't discriminating the selection value

0

@persianprez

My IF statement isn't working (or maybe its my entire function). When I run the code and fill in the form, the form is submitted to both text files because the if statement isn't discriminating the selection value

Did you write this code? What are you trying do to? Are you trying to write each strings on the same txt files or 2 different txt files?

Isn't it much easier just to used the if and else statement in php rather than javascript ?

0

I'm trying to write to 2 different files. If app is selected, the form should be submitted to ../apps/page1/raw_data.txt. If game is selected, the form should be submitted to ../games/page1/raw_data.txt. I'm not aware of how to do this with php.

1

On selection of game or app, If you want to update file on server, you must submit your page using post method or you can use jquery. But simple javascript can not update file on server.

Edited by urtrivedi

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.