...

View Full Version : Is javascript the right langauge for this?



inVINCEable
07-04-2007, 01:00 AM
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.

inVINCEable
07-04-2007, 04:05 PM
Please somebody has to know! :)

Philip M
07-04-2007, 06:46 PM
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>

inVINCEable
07-04-2007, 10:06 PM
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 ?

felgall
07-04-2007, 10:22 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum