Hello i want to pass a value with the id #allcountries.
html += '<option style="width:90%"><a href="'+v.country_id+'">'+v.nam+'' +'</a></option>';
<div id="allcountries"></div>


when i select a country it returns [object Object] on the alert when it should return the id of the country

You display the entire div. Either use:

alert($('#allcountries option:selected').val());


alert($('#allcountries option:selected').text());

It's strange that allcountries is a div and not a select

ok now it alerts tha name of the country i want to pass the id of the country like this
var country_id=$("#allcountries").val();

i use select like this

var html='<select style="width:90%" class="panel panel-heading"><option style="width:90%">Select a Country</option>';


html += '<option style="width:90%" value="'+v.country_id+'">'+v.nam+'' +'</option>';

OK IT WORKS. I wanted to use <a href because i wanted each country to be a link that when pressed returns value based on their country

i use this

var country_id=$("#allcountries option:selected").val();
        if($.trim(title).length>0 && $.trim(description).length>0 && $.trim(country_id).length>0 && /^[a-zA-Z0-9_ -]{3,100}$/i.test(name))
        /* Media Update */

and the php

function mediaUpdate()

$request = \Slim\Slim::getInstance()->request();
$data = json_decode($request->getBody());

$sql = "UPDATE messages SET title=:title,description=:description,country_id=:country_id WHERE msg_id=:msg_id and uid_fk=:uid";
    try {
        if($key==$data->token && strlen($title)>0 && strlen($description)>0 && strlen($country_id))

        $db = getDB();

        $stmt = $db->prepare($sql);
        $stmt->bindParam("title", $title,PDO::PARAM_STR);
        $stmt->bindParam("description", $description,PDO::PARAM_STR);
        $stmt->bindParam("country_id", $country_id,PDO::PARAM_STR);
        $stmt->bindParam("msg_id", $msg_id,PDO::PARAM_INT);
        $stmt->bindParam("uid", $uid, PDO::PARAM_INT);
        $db = null;
        echo '{"media": [{"msgID":"'.$msg_id.'"}]}';

    } catch(PDOException $e) {
        echo '{"rror":{"text":'. $e->getMessage() .'}}'; 

but it doesnt dtore the country_id

Member Avatar

I think you.ll find that was pritaeas not me

ok thaks to Pritaes too!!