Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2017
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    parameters from html button

    Hello everybody,

    I recently started making a little home server just for fun and ran into some problems with the website that controls the server itself. To elaborate, I have a bunch of HTML buttons, which trigger js-functions that call a php file. It's working as intended, though I have to create a new function for every button. Since they are all just executing one file, I imagine you can probably do that with just passing a parameter. So I tried this:
    Code:
    <script type = "test/javascript">function test (name) { $.ajax( { type : 'POST', url : name + ".php" }); }</script>
    Which did not seem to work. I also don't know how to call that function from HTML with a parameter. I tried:
    Code:
    <button onclick='test("file")'>TEST</button>
    Again not working though I can't tell why (I have very little experience with anything aside from C/C++). Help would be greatly appreciated.

  2. #2
    Regular Coder
    Join Date
    Sep 2010
    Location
    U S of A
    Posts
    291
    Thanks
    6
    Thanked 48 Times in 48 Posts

  3. #3
    Master Coder sunfighter's Avatar
    Join Date
    Jan 2011
    Location
    Washington
    Posts
    7,998
    Thanks
    36
    Thanked 1,072 Times in 1,068 Posts
    Since they are all just executing one file just place this in all buttons
    <button onclick='test();'>TEST</button>
    Nothing needs to be passed.
    The JS looks like this:
    Code:
    function test(){
    window.location.href = "ajax.php";
    }
    You don't need ajax unless you want to change the DOM of your page.

    You don't give enough info to give you a good answer.
    Evolution - The non-random survival of random variants.
    Physics is actually atoms trying to understand themselves.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •