im asking can it be done??!
with example plz
thanks

Recommended Answers

You tagged this with php. Why would you want to do this with js? It can certainly be done by passing the js to the server (php then deals with it). However, you really shouldn't. If you set it up like this, any user could send an SQL statement to …

Jump to Post

Why can't you use php? That's one point of a server side language - you can hide the workings from the end user. Can you show any code that you've tried with php? You've tagged this article with php, so I assume that you know how to use it - …

Jump to Post

All 6 Replies

Member Avatar

You tagged this with php. Why would you want to do this with js? It can certainly be done by passing the js to the server (php then deals with it). However, you really shouldn't. If you set it up like this, any user could send an SQL statement to the specified url and you could end up sharing all your secret data or getting it deleted.

If this is not anything to do with a full SQL statement, then yes, you can send ajaxified data to an url and you can apply filters etc.

If you are asking about filtering an exisiting js object, then be more specific.

only a select statement , and which i trying to do is adding a drop menu(its data come's from the mysql) when i click a button
i know its a bad practies but cant find another way around

Member Avatar

Why can't you use php? That's one point of a server side language - you can hide the workings from the end user. Can you show any code that you've tried with php? You've tagged this article with php, so I assume that you know how to use it - at least as a beginner.

<html><scrip>tar choices = ["one", "two"];

function addInput(divName) {
    var newDiv = document.createElement('div');
    var selectHTML = "";
    selectHTML="<select>";
    for(i = 0; i < choices.length; i = i + 1) {
        selectHTML += "<option value='" + choices[i] + "'>" + choices[i] + "</option>";
    }
    selectHTML += "</select>";
    newDiv.innerHTML = selectHTML;
    document.getElementById(divName).appendChild(newDiv);
}
</script>
<body>
<form class="new" method="post" action="/jobs">
    <div id="dynamicInput"></div>
    <input type="button" value="Add" onclick="addInput('dynamicInput');" />
    <input type="button" value="Save" />
</form>
</body>
</html>

what i need is to replace the drop down menu value with a select data from mysql
,and yes i should have taged it with javascript too (my fault)

Member Avatar

Bit confused. You can fill data from mysql via php prior to the page loading on the client (browser) OR / AND you can send a js (ajax) msg to the server to request new data to update certain areas of the page.

Do you need to change the data in the dropdown once the page has loaded? If not - just use PHP and forget the JS.
I'm assuming you know how to create a dropdown in PHP?

//assume $rows holds your data from mysql:

$str ='';
foreach($rows as $r){
    $str .= "<option value=\"{$r['id']}\">{$r['label']}</option>\n"
}

//Then...

<select>
    <?php echo $str;?>
</select>

Maybe I'm missing the point.

I'm sorry , but i belive there is a misunderstanding.
i need a drop down menu (its data don't change (it comes from a table)) with onclick event
that why i need it to with js.
and thank you from replying :)

Be a part of the DaniWeb community

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