This is a topic selector made in <a> tag in php. Once user click on trigger, the function pass value from the original <a> tag to another <input> tag for display purpose. then when user submits form, ajaxForm is called out to handle the rest.
js.file:
function selectopic(topic_selector_name){
$('#topicidselected').val($(topic_selector_name).val());
// alert ($('#topicidselected').val());
$('#topicidselected').text($(topic_selector_name).val());
$('#topicselected').text($(topic_selector_name).text());
}
$('.topicselect').click(function(){
selectopic($(this));
});
$('#newentryform').ajaxForm({
target: '#para1',
resetForm: true,
});
problem is, we suppose to have $_POST={"entry":"blahblahblah","topicid":"122","date":"12\/06\/12","privacy":"onlyme"}
but instead, it gives me Notice: Undefined index: topicid in D:\wamp\www\projectdiary\diary\php\_newentry.php on line 2
{"entry":"blahblahblah","topicid":null,"belongdate":"12\/06\/12","privacy":"onlyme"}
php.file:
$arr = array( 'entry' => $_POST['entry'], 'topicid' => $_POST['topicid'], 'date' => $_POST['date'], 'privacy' => $_POST['privacy']);
echo "We have saved your entry, this is how it looks like: <br />";
echo json_encode( $arr );
You can see in js.file I used alert to check the value after passed in. It is a correct number “122”.
I’m a noob, I need your help.
Thanks.
Why are you assigning the value to
topicselectedand setting thetextproperty (not proper use, see the docs)? You’re clickingatags and getting theval()of them? See the docs there: http://api.jquery.com/val/ — also not valid. Maybe I’ve misunderstood you?I think you’re trying harder than you have to, this could be accomplished in one line:
jsFiddle: http://jsfiddle.net/KNERB/