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>

alert($("#allcountries"));

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());

or:

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>';

Use:

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 */
        mediaUpdate(uid,token,apiBaseUrl,baseUrl,editMsgID,title,description,country_id);  

and the php

function mediaUpdate()
{

$request = \Slim\Slim::getInstance()->request();
$data = json_decode($request->getBody());
$uid=$data->uid;
$msg_id=$data->msg_id;
$title=$data->title;
$description=$data->description;
$country_id=$data->country_id;

$sql = "UPDATE messages SET title=:title,description=:description,country_id=:country_id WHERE msg_id=:msg_id and uid_fk=:uid";
    try {
        $key=md5(SITE_KEY.$data->uid);
        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);
        $stmt->execute();
        $db = null;
        echo '{"media": [{"msgID":"'.$msg_id.'"}]}';

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

but it doesnt dtore the country_id

ok i did thanks Diafol

Member Avatar for diafol

I think you.ll find that was pritaeas not me

ok thaks to Pritaes too!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.