...

View Full Version : Form submit does not work



phpchick
02-25-2012, 12:41 AM
the showUser function has ajax in it that calls a php file that accesses a db to perform some calculations.

I wanted to use the clicked function to force required dropdowns to be selected but I cannot seem to get the submit button to do anything. It does nothing when you click it. Not sure how to proceed, have looked everywhere. If anyone has any advice I would really appreciate it.





<form id="forecastfilter" action="indexo_beats.php" method="get" onsubmit="clicked(this.value='yes')">

<div class="fc">Date:</div>
<select name="date" onchange="showUser(this.value)">
<option value="">--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
<option value="Date: Past Hour">Past hour</option>
<option value="Date: Past week">Past week</option>
<option value="Date: Past month">Past month</option>
<option value="Date: Past year">Past year</option>
</select>

<br />
<div class="fc">Wideouts:</div>
<select name="wideouts" onchange="showUser(this.value)">
<option value="">--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
<option value="Wideouts: Higher">Revised Higher</option>
<option value="Wideouts: Unchanged">Remains Unchanged</option>
<option value="Wideouts: Lower">Revised Lower</option>
</select>

<br />
<div class="fc">QBs:</div>
<select name="qbs" onchange="showUser(this.value)">
<option value="">--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
<option value="QBs: beat">Above Analyst Estimates</option>
<option value="QBs: inline">Inline with Analyst Estimates</option>
<option value="QBs: miss">Below Analyst Estimates</option>
</select>

<br />
<div class="fc">Football:</div>
<select name="football" onchange="showUser(this.value)">
<option value="">--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
<option value="Football: beat">Above Analyst Estimates</option>
<option value="Football: inline">Inline with Analyst Estimates</option>
<option value="Football: miss">Below Analyst Estimates</option>
</select>

<br />
<div class="fc">Sentiment:</div>
<select name="sentiment" onchange="showUser(this.value)">
<option value="">--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>
<option value="Sentiment: good">Good</option>
<option value="Sentiment: neutral">Neutral</option>
<option value="Sentiment: bad">Bad</option>
</select>
<div class="searchbutton">
<input type="button" value="Search Draft" />
</div>
</form>

Old Pedant
02-25-2012, 01:02 AM
What "submit button"?? You don't have one. You have a button, but (a) it is not a submit button and (b) it has no onclick action specified so indeed it does nothing at all.

Further, your onsubmit function for the <form> makes no sense.



onsubmit="clicked(this.value='yes')"

The this in there refers to the <form> tag. A <form> tag does not *HAVE* a .value property. So that JavaScript would give an error. And an error in the JS means the <form> will then be submitted, no matter what.

phpchick
02-25-2012, 07:36 AM
Further, your onsubmit function for the <form> makes no sense.



onsubmit="clicked(this.value='yes')"

The this in there refers to the <form> tag. A <form> tag does not *HAVE* a .value property. So that JavaScript would give an error. And an error in the JS means the <form> will then be submitted, no matter what.

I simply want to send the word "yes" to my function called clicked... wasn't sure how to do this. sorry confused

phpchick
02-25-2012, 07:55 AM
I am so damn confused.... Nothing is working

BODY


<body>
<form id="filter" action="index.php" method="get" onsubmit="clicked()">
<div class="filtercaption">Date:</div>
<select name="date" onchange="showUser(this.value)">
<option value="">--</option>
<option value="Date: Past Hour">Past hour</option>
<option value="Date: Past week">Past week</option>
<option value="Date: Past month">Past month</option>
<option value="Date: Past year">Past year</option>
</select>
<input type="submit" value="Search Draft" />
</form>


HEADER, specifically the the clicked() function


function clicked()
{
xmlhttp.open("GET","getselection.php?q=clicked",true);
xmlhttp.send();
}


getselection.php



<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'username', 'password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("nameofdb", $con);
$ip=$_SERVER['REMOTE_ADDR'];
$sql="INSERT INTO counter (selection, ip) VALUES ('".$q."','".$ip."')";

$result = mysql_query($sql);


mysql_close($con);
?>





All i want to do is put the word "clicked" into a mysql table when a user hits my submit button.

glenngv
02-25-2012, 01:24 PM
Why don't you just do the click tracking in indexo_beats.php which is the form action?

phpchick
02-25-2012, 03:56 PM
Why don't you just do the click tracking in indexo_beats.php which is the form action?

I'll try this, ty

Logic Ali
02-25-2012, 04:51 PM
function clicked()
{
xmlhttp.open("GET","getselection.php?q=clicked",true);
xmlhttp.send();
}



You're setting-up an asynchronous request them immediately dismissing the page. I would either use a synchronous request or return false and use the readystatechange handler to submit the form.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum