0

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

Edited by SimonIoa: ss

3
Contributors
8
Replies
32
Views
1 Year
Discussion Span
Last Post by SimonIoa
0

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

0

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

2

Use:

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

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

0

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

0

I think you.ll find that was pritaeas not me

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.