Announcement

Collapse
No announcement yet.

HTML/Java Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • HTML/Java Help

    So, I have the need to produce a very simple web page that would allow for a user on a VERY secure intranet to edit the page, push SAVE, and have the text save to a file on the same web server. The path/name of the file would be fixed and non editable by the user. My basic layout is below.



    Here's the code so far. Stupid simple stuff. However, I have a question on where to go next. How do I power the buttons? I mean, I know what I want to do, save text to the file, delete the file, etc. but, how do I go from showing buttons to having them actually do something? (I'd prefer to stay in javascript if I can.)

    Note: The environment is NOT an IIS server and I already have some javascript running. (I believe the Web server is Tomcat.)

    Code:
    <!DOCTYPE html>
    <html>
    <body>
    
    <h1> Message tester</h1>
    
    <p>Enter the desired text below</p>
    
    <form>
    <textarea rows="10" cols="90">
    </textarea>
    <p>
    
    <input type="submit" value="Save"> < input type="submit" value="Delete Current">
    </form>
    </body>
    </html>
    Thanks!

    Edit: I'll be changing this up as I try and figure it out....

    More to work with
    Code:
    <!DOCTYPE html>
    <html>
    <body>
    
    <h1>Message tester</h1>
    
    <p id="MessageArea">
    Enter the desired text below
    </p>
    
    <script>
    function SaveText()
    {
    document.getElementById("MessageArea").innerHTML="This would save!";
    }
    
    function DeleteCurrent()
    {
    document.getElementById("MessageArea").innerHTML="This would delete!";
    }
    </script>
    <form>
    
    <input type="text" id="mytextbox" value="Hello World!" />
    
    
    <p>
    
    <button type="button" onclick="SaveText()">Save</button>
    <button type="button" onclick="DeleteCurrent()">Delete Current</button>
    </form>
    </body>
    </html>
    Last edited by Darren M; 12-02-2012, 11:45 AM. Reason: editing
    Originally posted by Taya Kyle, American Gun
    There comes a time when honest debate, serious diplomatic efforts, and logical arguments have been exhausted and only men and women willing to take up arms against evil will suffice to save the freedom of a nation or continent.

  • #2
    You're going to need some programming on the server side to actually do stuff. You don't need JavaScript unless you want to validate client side, but you'd need to set your form's method to post, action to the URL of the edit script, and the textbox text would automatically get added to the request parameters. Add another form with method post and action set to the delete script around the delete button and you're in business.

    HTML Code:
    <html>
    <form method="post" action="edit.php">
    <input type="hidden" id="id" value="12345" />
    <textarea id="txtContent" />
    <submit name="edit" value="edit" />
    </form> <!-- submit automatically redirects to edit.php and passes the I'd and txtContent values to the script -->
    
    <form method="post" action="delete.php">
    <input type="hidden" id="id" value="12345" />
    <submit name="delete" value="delete" />
    </form> <!-- submit automatically redirects to delete.php and passes the ID to the script -->
    </html>
    The real work is done server sside in those scripts. It can be any language your server supports (PHP, Perl, Python, JSP, ASP, etc.) I just chose PHP because it's the most common and easiest to pick up. I prefer Perl, though.
    Originally posted by Broncojohnny
    HOORAY ME and FUCK YOU!

    Comment


    • #3
      HTML Code:
      // edit.php or delete.php
      <?php
      
      if( isset($_POST['id']) ) {
          echo "I just got an edit or delete for ID {$_POST['id']}";
      }
      
      ?>
      I've been writing a lot of PHP lately. Getting a database up and running is a little bit more challenging for a newcomer.
      2004 Z06 Commemorative Ed.

      Comment


      • #4
        Some simple code i wrote for this racist site I run.

        You can submit your post to the url.php with this in it, and it'll write to the file whatever was in the box.

        Code:
        <?
        
        if( isset($_POST['submit'])){
                if(isset($_POST['url'])){
                        $ip = $_SERVER['REMOTE_ADDR'];
                        print "YOUR SHIT WAS SUBMITTED: \"". $_POST['url']."\" @ $ip";
                        $file = ".urls.txt";
                        $output = date(U) . " :::: ".$_POST['url']." :::: ".$ip ."\n";
                        file_put_contents($file, $output, FILE_APPEND | LOCK_EX);
                }
        }else{ 
                print "WARNING: YOU ARE CLEARLY A STUPID ****** SINCE THE URL SUBMITTED WAS BLANK.\n";
        }

        Comment


        • #5
          LOLz!
          Originally posted by Broncojohnny
          HOORAY ME and FUCK YOU!

          Comment


          • #6
            If the webserver is Tomcat then you probably do not have PHP running.. It is probably Java (which is not Javascript)

            Javascript is client side. Like a fancy extension of HTML meaning it only enhances the users experience by making the browser do flashy things.

            I can show how it's done in PHP but I'm not too sure on the Java end of things but it would be similar in concept (except it's a lot harder to setup and configure java)

            PHP Code:
            <?php
            $text 
            "This what I want to write to the file";

            $file fopen("file.txt""w");
            fwrite($file$text);
            fclose($file);

            ?>
            Last edited by Marklar; 12-02-2012, 10:32 PM.

            Comment


            • #7
              For a bit of closure. I was able to accomplish this with 2 pages. The main one shown above and another resulting from a Perl script called from the SAVE/DELETE buttons. As the page is in a production state I can not [legally] post the end results. HOWEVER, if anyone needs help w/ this stuff in the future just hit me up. I'm no expert but I sure do get lucky a lot. Thanks for the help and suggestions!! You guys keep me going when I think my ideas are stupid!
              Originally posted by Taya Kyle, American Gun
              There comes a time when honest debate, serious diplomatic efforts, and logical arguments have been exhausted and only men and women willing to take up arms against evil will suffice to save the freedom of a nation or continent.

              Comment

              Working...
              X