views:

43

answers:

3

Hello so i have this form:

<form action="javascript:DoSCInsert()" method="post">
<textarea onfocus="this.cleared=true;javascript:clearContents(this);" rows="5" cols="40" id="comment" name="comment">...</textarea>
Yes: <input type="radio" value="Y" id="SCvoteY" name="vote"></input>  No: <input type="radio" id="SCvoteN" value="N" name="vote"> </input>
<input type="hidden" name="fID" id="fID" value="<? echo $_GET["id"]; ?>" />
<input onsubmit="if (!this.comment.cleared) clearContent(this.comment); return true;" type="submit" name="Submit" value="Stem!"/> 
</form>

Anyway so i have this javascript also that tranfers the output info to insertSC.php:

function DoSCInsert(){
    $("#SCres").html("to sek..");
    var nocache = '0';
    var data = { fID : $("#fID").val(), SCvote : $("#SCvoteY").val(), SCvote : $("#SCvoteN").val(), comment: $("#comment").val(), nocache: nocache };
    $.get('insertSC.php', data, onSCInsertComplete);
}
function onSCInsertComplete(data,textstatus){
    $("#SCres").html(data);
}

and in my insertSC.php i have this:

<?php
echo $_GET['comment']." - ".$_GET['SCvoteY'];
?>

Now i get out comment but no SCvoteY.... this is just a test i made, what i was really making is that you vote Y or N and then it inserts into the vote column Y or N(what you pickd) now i couldnt figure how to do it/something went wrong somewhere and now i cant even get out SCvoteY i just get undefined index

What i need help with is what i just mention i want to when you either choose Y or N it should output what you choose. If you didnt choose any (empty isset?) then false.. else echo Y or N(what you picked)

A: 

That's because the name of your radio button is "SCvote", not "SCvoteY"... You need to get the value of "SCvote" which will be either "N" if they selected no, "Y" if they selected yes, or "" if they never selected one. Edit: I'm not sure exactly how the jQuery GET thing works, but I'm pretty sure you're always going to get the no value since you're defining both of them in the data rather than checking which one is selected and defining only that one.

How radio buttons work: Each one should have the same name, in this case "vote", which makes it so only one button in the group can be selected. When you submit that data, the value is the value defined for the one that was selected when it was submitted, or blank if none were selected. Getting the value by ID will always return the value defined, you need to be checking if it is checked. The checked value will be either true or false based on whether that button is the one that is currently selected.

animuson
how to check then? i mean out from my code, instead of $_GET["SCVoteY"]; how should i echo out from the "vote" name?
Karem
A: 

As far I can tell you pass SCvote into insertSC.php twice, but not SCvoteY. It is just a typo. Since you use it twice, the SCvoteN will always overwrite its value and you try to echo SCvoteY, which you dont have.

realshadow
A: 

Use JQuery's .serialize() instead of parsing the output yourself.

Edit You need to do three things:

  1. (optional) Remove id attrib of your radio buttons - they're not needed
  2. Change DoSCInsert() function to use .serialize()
  3. Change your PHP code to look for the right parameter name.

The code snips follow:

HTML

<form action="javascript:DoSCInsert()" method="post">
<textarea onfocus="this.cleared=true;javascript:clearContents(this);" rows="5" cols="40" id="comment" name="comment">...</textarea>
Yes: <input type="radio" value="Y" name="vote"/>  No: <input type="radio" value="N" name="vote">
<input type="hidden" name="fID" id="fID" value="<? echo $_GET["id"]; ?>" />
<input onsubmit="if (!this.comment.cleared) clearContent(this.comment); return true;" type="submit" name="Submit" value="Stem!"/> 
</form>

JS

function DoSCInsert(){
    var data = $('form').serialize();
    $.get('insertSC.php', data, onSCInsertComplete);
}

PHP

echo $_GET['comment']." - ".$_GET['vote'];

Lastly, you don't need a closing tag for input, type radio; so I also took out the two </input>s.

Majid
can you give me example please i dont understand so much from the jquery database
Karem