You didn't answer the question about script errors.
Anyways, see:
http://www.prototypejs.org/api/form/element/getValue
$F() is an alias for that. It requires an id or the element itself, so all of the inputs need id's. However, with moneyline you cannot do that. I made up a function to take care of that.
Here's the script code I used:
Code:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js"></script>
<script type="text/javascript">
function sendRequest() {
function getMoneyline(){
var ml = $('test').elements['moneyline'];
for (var i = ml.length - 1; i > -1; --i){
if(ml[i].checked) return $F(ml[i]);
}
return '';
}
new Ajax.Request("bet.php",
{
method: 'post',
parameters: {
amount: $F('amount'),
bet_kind: $F('bet_kind'),
gamenumber: $F('gamenumber'),
sporttype: $F('sporttype'),
moneyline: getMoneyline(),
user_id: $F('user_id')
},
onComplete: showResponse
}
);
}
function showResponse(req){
$('show').innerHTML = req.responseText;
}
</script>
Here's the form:
Code:
<form id="test" onsubmit="return false;">
<input type="hidden" name="bet_kind" id="bet_kind" value="0">
<input type="hidden" name="gamenumber" id="gamenumber" value="5">
<input type="hidden" name="sporttype" id="sporttype" value="Baseball">
<input type="hidden" name="user_id" id="user_id" value="Bob">
<input type="checkbox" name="moneyline" value="Marlins">Marlins vs <br>
<input type="checkbox" name="moneyline" value="Phillies">Phillies<br>
$<input type="text" name="amount" size="3" maxlength="3" id="amount" >
<input type="submit" value="Bet" onclick="sendRequest();">
</form>
Notice the id's for each form element except moneyline for which I made a custom function. I also filled in the PHP tokens in the form with hard coded values consistent with what I guessed they could be because I have nowhere to pull those values from. But you may replace my hard coded values with your PHP tokens again, as long as they resolve to something usable by the form (they should, the earlier test tends to confirm that) and you keep the added id's:
Code:
<form id="test" onsubmit="return false;">
<input type="hidden" name="bet_kind" id="bet_kind" value="0">
<input type="hidden" name="gamenumber" id="gamenumber" value="<?php echo $feed->events->event->gamenumber;?>">
<input type="hidden" name="sporttype" id="sporttype" value="<?php echo $feed->events->event->sporttype;?>">
<input type="hidden" name="user_id" id="user_id" value="<?php echo $find_user_id1[0];?>">
<input type="checkbox" name="moneyline" value="<?php echo $game->periods->period->moneyline->moneyline_visiting; ?>"><?php echo $game->periods->period->moneyline->moneyline_visiting; ?> vs <br>
<input type="checkbox" name="moneyline" value="<?php echo $game->periods->period->moneyline->moneyline_home; ?>"><?php echo $game->periods->period->moneyline->moneyline_home; ?><br>
$<input type="text" name="amount" size="3" maxlength="3" id="amount" >
<input type="submit" value="Bet" onclick="sendRequest()">
</form>
Added Later:
This could be made reusable for - say multiple forms with the same fields on the same page, or as an external script used by many pages with one or more forms on it that have those fields. If you're interested in that, let me know.
Also - the checkboxes should be radio buttons. Otherwise both could be checked.
Bookmarks