2
Contributors
6
Replies
44
Views
5 Months
Discussion Span
Last Post by abubaker_2
0

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.

0

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

1

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.

0
<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)

0

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.

0

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 :)

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.