Welcome to WebmasterWorld Guest from 54.159.165.175

Forum Moderators: coopster & jatar k

Using Submit Button with Java roll()

I would need help in turning java roll() into a solution so I can useSubmit

   
9:51 am on Mar 9, 2010 (gmt 0)

5+ Year Member



I have this on game.php

<a href="javascript:open2('questions.php','0')" style="border:none"
onmouseover="roll('q10a', 'images/index_11_b.gif')"
onmouseout="roll('q10a', 'images/index_11.gif')" onClick="javascript:showlinks('q10a')">
<img src="images/index_11.gif" width="204" height="132" alt="" name="q10a" hspace="0" vspace="0" border="0" id="q23"/></a>


And this on questions.php

<?php
require 'connect.php';
if($_POST['submit']=='Questions')
{
$q = $_GET['q'];
$postid = $_SESSION['id'];
$query = "Select * FROM tz_members WHERE id='$postid'";
$row2 = mysql_fetch_array(mysql_query($query));
echo $row2['$q'];
}
?>

The main point is that the value sent through the $_GET should be searched with the SESSION=['id'] and then displayed what is in the Mysql. So how could I possibly change the upper part so that the picture get switched when the mouse goes over and then back when the mouse removes and also if its clicked it sends a ?q=sth (in this case would be q=q10a) value to questions.php?
10:00 am on Mar 9, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



hi there Barnamedve,

Welcome to webmaster world!

The query needs tweeking:-


$query = "SELECT * FROM `tz_members` WHERE `id` ='".$postid."' ";
$getdata = mysql_query($query)
$row2 = mysql_fetch_array($getdata) or die(mysql_error());


Try this, and when your doing this:-

if($_POST['submit']=='Questions')
{


try doing this first:-

if(isset($_POST['submit']) && ($_POST['submit'] == "questions"))
{


This way, the clause only executes if the $_POST is set and equals "questions".

Good luck,

Cheers,

MRb
10:47 am on Mar 9, 2010 (gmt 0)

5+ Year Member



Hey Matthew1980!
Thanks I think it was a good choice to sign up since it seems that there are quite a few people who are eager to help. My website is actually a jeopardy game I mean the game.php and the reason I need this is that when a person goes on with the mouse it shows a lighter version of the picture which i created in photoshop and when it removes it brings back the original and when it clicks (I decided to use POST instead of GET) it sends a POST with the value of questions and the value that will be recognised by the script above so the clicked question will show up in questions php and I dont have to do 50 questions.php!

here is how it looks the questions.php right now. The other did not change



<?php
require 'connect.php';
if(isset($_POST['submit']) && ($_POST['submit'] == "questions"))
{
$q = $_POST['q'];
$postid = $_SESSION['id'];
$query = "Select * FROM 'tz_members' WHERE 'id'='".$postid."'";
$getdata = mysql_query($query)
$row2 = mysql_fetch_array($getdata) or die(mysql_error());
echo $row2['$q'];
}
?>
12:17 pm on Mar 9, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Hi there Barnamedve,

Could you not achieve this through css? there is an instruction in css called hover: that allows you to alter the img if you want, ie two class's identically set but one has the prefix of hover: In this class you can stipulate a different picture from the first class, this is how I do quite similar on my own projects, I try to steer clear of js as not all browsers support & quite often people turn off. Just my own opinion there.

Nevertheless, check to see what is being posted by doing a print_r($_POST); directly after the form is submitted (in the file that you stipulated as the action) from there echo to see how the data is being processed & always echo the $sql query before its actioned to see how the query is being populated, from there you can see where you are going wrong, if at all ;-p

Hope some of that helps,

Cheers,

MRb
2:28 am on Mar 10, 2010 (gmt 0)

5+ Year Member



Coul you give me an example of code because I checked it and it only showed how to put colors but even if I find out because I kinda get it how could I use that in the <input> tag so the clicked link sends $_POST?
8:15 am on Mar 10, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I'm not sure it's possible to actually change what an image is inside an <img> tag with CSS on hover (If I'm wrong I can take being corrected :)), but you could achieve the same effect with a <div>:

div.someClassName {
width: 100px;
height: 100px;
background: url('/images/someImageName_1.png');
}

div.someClassName:hover {
width: 100px;
height: 100px;
background: url('/images/someImageName_2.png');
}

To make it submit the form, you could do this:

<div class="someClassName" onclick="document.forms['someFormName'].submit()">&nbsp;</div>
<noscript><input type="submit" name="submitButton" value="Submit" /></noscript>

Or you could even make a transparent image the same size (very easy to do in PhotoShop - probably best to use a gif for older browser support) and do the following:

<div class="someClassName"><input type="image" src="/images/SomeTransparentImageName.gif" alt="Submit" /></div>

(Input type="image is ALWAYS submit)
9:37 am on Mar 10, 2010 (gmt 0)

5+ Year Member



Thanks for the reply!

The script seems to work, but a quick question:

Since its a submit button I have to put <from method="post" action="questions"
then after the input </form> ?
10:45 am on Mar 10, 2010 (gmt 0)

5+ Year Member



Everything is working fine except the main point! The form is not sending anything! It just loads the other page without giving any value. How can I give value and name to the javascript so it actually sends something! Should I do a hidden input with a default value? Or what should I do?
11:20 am on Mar 10, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Your first post:

Yes, the form tags are required

---

Your second post:

A form can only send the data captured by it's inputs.

<input type="checkbox...
<input type="file...
<input type="hidden...
<input type="password...
<input type="radio...
<input type="text...

or a <textarea></textarea>

With none of the above, the form isn't sending much of use.

On questions.php you then need to use the PHP $_POST superglobal to pick up each value from the form, so:

$someVariableName = $_POST['someFormElementName'];
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month