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 5 of 5
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    85
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Is javascript the right langauge for this?

    I apologize, I am fairly new to javascript, just have some brief knowledge of using the jquery library.

    What I want to do is create a button that changes state after a use has voted on it, if anyone is familiar with the website digg, then this is very much the case, I want to be able to change the button state to "voted" or something like that after a user has voted on that. Thanks for any advice pointers.

    Also, I would like it to insert a value into a mysql db as well, I am using PHP too.
    I am on my way. :)

  • #2
    New Coder
    Join Date
    Apr 2007
    Posts
    85
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Please somebody has to know!
    I am on my way. :)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Not sure what you mean exactly by "change state" but if you mean change the value/and or color then here is an outline:-

    <form action="http://yoururl.com/cgi-bin/............."
    method="POST" name="Voting Form" onSubmit="return submitForm(this.Submitbutton)">

    <div align="center"><center><font face="Arial"><input type="submit" name="Submitbutton" value="Vote By Clicking Here" style="font-size:'11pt'; font-weight:'700'; background-color:'#00CC33'; border-width:'3'; border-color: '#00CC33'"></font></center></div>

    </form>

    <script type = "text/javascript">
    var sub = false;

    function submitForm(s) { // when submit form button pressed
    s.value = " You have voted ..... ";
    if (sub) {return false} // sub = true so form already submitted
    else { // if sub = false
    sub = true; // set sub = true
    return sub;
    }
    }
    </script>

  • #4
    New Coder
    Join Date
    Apr 2007
    Posts
    85
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Not sure what you mean exactly by "change state" but if you mean change the value/and or color then here is an outline:-

    <form action="http://yoururl.com/cgi-bin/............."
    method="POST" name="Voting Form" onSubmit="return submitForm(this.Submitbutton)">

    <div align="center"><center><font face="Arial"><input type="submit" name="Submitbutton" value="Vote By Clicking Here" style="font-size:'11pt'; font-weight:'700'; background-color:'#00CC33'; border-width:'3'; border-color: '#00CC33'"></font></center></div>

    </form>

    <script type = "text/javascript">
    var sub = false;

    function submitForm(s) { // when submit form button pressed
    s.value = " You have voted ..... ";
    if (sub) {return false} // sub = true so form already submitted
    else { // if sub = false
    sub = true; // set sub = true
    return sub;
    }
    }
    </script>

    Ah! Thank you so much! I have looked into this and so far I have gotten the visual part right, but what about the backend? How can I use javascript to interact with my database? Or is this not possible ?
    I am on my way. :)

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    You need to read up on 'Ajax' which is the way that JavaScript can call a server side script. That server side script can then do all the database accesses and return the result back to the JavaScript.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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